GithubHelp home page GithubHelp logo

doc22940 / snapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from filamentgroup/snapper

0.0 1.0 0.0 1.29 MB

A CSS Snap-Points based carousel (and lightweight polyfill)

License: MIT License

CSS 10.33% JavaScript 87.73% HTML 1.94%

snapper's Introduction

snapper

A CSS Snap-Points based carousel (and lightweight polyfill)

MIT License [c] 2015 Filament Group, Inc

Dependencies

  • jQuery or similar DOM library
  • The toss() extension (optional, for smoothened anchoring and scroll snapping). Run $ npm install to download a copy to ./node_modules/fg-toss/src/toss.js

Demo

View the Snapper demos:

Docs

  1. Include dependencies, plus the css and js files in the src dir.
  2. Use the markup pattern below.
<div class="snapper">
	<div class="snapper_pane">
		<div class="snapper_items">
			<div class="snapper_item" id="img-a">
				<img src="a-image.jpg" alt="">
			</div>
			<div class="snapper_item" id="img-b">
				<img src="b-image.jpg" alt="">
			</div>
			<div class="snapper_item" id="img-c">
				<img src="c-image.jpg" alt="">
			</div>
			<div class="snapper_item" id="img-d">
				<img src="d-image.jpg" alt="">
			</div>
		</div>
	</div>
</div>
  1. Trigger an "enhance" event on a parent of the markup to initialize. You might do this on domready, as shown below:
$( function(){
	$( document ).trigger( "enhance" );
});

Adding thumbnails

To add thumbnail or graphic navigation to the carousel, you can append the following markup to the end of the snapper div (substituting your own styles, images, and hrefs to correspond to the IDs of their associated slides):

<div class="snapper_nav">
	<a href="#img-a"><img src="a-thumb.jpg" alt=""></a>
	<a href="#img-b"><img src="b-thumb.jpg" alt=""></a>
	<a href="#img-c"><img src="c-thumb.jpg" alt=""></a>
	<a href="#img-d"><img src="d-thumb.jpg" alt=""></a>
</div>

Adding next/prev navigation

To add next and previous links that persist state, you can add a data-snapper-nextprev attribute to the snapper div.

<div class="snapper" data-snapper-nextprev>
	...
</div>

Showing multiple images at a time

To make snapper respect the CSS-specified widths of items in a slider, you can add the data-snapper-setwidths attribute to the snapper div. This allows you to show more than one image at a time, and even adjust that as viewport width allows. See example: https://fg-snapper.netlify.com/demo/breakpoints.html

<div class="snapper" data-snapper-setwidths>
	...
</div>

Hiding the scrollbar

In some browsers, native scrollbar handles can be pretty ugly across the bottom of the carousel. As long as you're using thumbnails or some means of advancing the slides, you can wrap the snapper_pane in a div with a class of snapper_pane_crop and it'll hide the scrollbar from sight.

<div class="snapper">
	<div class="snapper_pane_crop">
		<div class="snapper_pane">
			<div class="snapper_items">
				<div class="snapper_item" id="img-a">
					<img src="a-image.jpg" alt="">
				</div>
				<div class="snapper_item" id="img-b">
					...
				</div>
				<div class="snapper_item" id="img-c">
					...
				</div>
				<div class="snapper_item" id="img-d">
					...
				</div>
			</div>
		</div>
	</div>
	<div class="snapper_nav">
		<a href="#img-a"><img src="a-thumb.jpg" alt=""></a>
		<a href="#img-b"><img src="b-thumb.jpg" alt=""></a>
		<a href="#img-c"><img src="c-thumb.jpg" alt=""></a>
		<a href="#img-d"><img src="d-thumb.jpg" alt=""></a>
	</div>
</div>

Support

CSS Snap Points support can be found here: CSS Snap Points on Caniuse.com This plugin is tested to work broadly across modern browsers, and as long as you use thumbnail navigation, it will even work in browsers that do not support overflow scrolling properly (such as Android 2.x browser).

snapper's People

Contributors

scottjehl avatar johnbender avatar zachleat avatar toddparker avatar agcolom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.