Smooth-action Carousel Scrolling with jQuery
jqRevolve is a plugin for jQuery to help you add scrolling content areas to your webpage(s).
Features;
I wanted a small, easy to understand and modify "carousel" scrolling compontent. There are plenty of other carousel-like plugins out there, however none had the basic auto-sizing and pressure-based scrolling features I needed.
If you like my plugins, please consider a dontation to support their development:
Current Version: 2008.11.13 +r2
© 2008 Brice Burgess - released under both the MIT and GPL licenses.
Download the Development Plugin (jquery.revolve.js - 5.42k)
Download the Production Plugin (jquery.revolve.packed.js - 2.29k)
** requires [jQuery >= 1.2.0+]
If you need support or have comments, please post to the jQuery mailing list.
Usage
To add a revolver to your website you must ...See the 'HTML' tab of the below examples for reference.
NOTE: The clip region should have relative, fixed, or absolute positioning and MUST have its overflow style set to hidden. The content container MUST have absolute posistioning. jqRevolve will automatically enforce these CSS rules.See the 'Javascript' tab of the below examples for reference.
Methods
$('#revolver').jqRevolve();
$('.revolvers').jqRevolve({autoSize:false, content:'div.carouselContent'});
$('#revolver').jqrRefresh();
$('.revolvers').jqrRefresh();
Parameters
Parameters allow tailoring the behavior of any jqRevolve to your needs. They are passed on-the-fly as an object to the $.jqRevolve function.(boolean) - default: true
(boolean) - default: true
(integer) - default: 0
(integer) - default: 230
(mixed) - default: '.revolve-next'
(mixed) - default: '.revolve-prev'
(mixed) - default: '.revolve-content'
Examples
$().ready(function(){ $('#example1').jqRevolve(); });
#example1 { /* MUST be relative or absolute! */ /* Plugin will automatically set if not. */ /* See example 2 CSS */ position: relative; /* MUST be hidden! */ /* Plugin will automatically set if not. */ /* See example 2 CSS */ overflow: hidden; width: 360px; margin: 10px 24px; border: 1px solid black; } #example1 .revolve-content { /* MUST be relative or absolute! */ /* Plugin will automatically set if not. */ /* See example 2 CSS */ position: absolute; z-index: 5; } #example1 .revolve-next, #example1 .revolve-prev { position: absolute; background-color: red; width: 25px; height: 100%; z-index: 10; } #example1 .revolve-next { right: 0; }
<div id="example1"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> jqRevolve - CLICK THE RED BLOCKS TO SCROLL THROUGH THIS CONTENT! AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ Viola! Fin. </div> </div>
$().ready(function(){ // Start mid-way (50%) through content $('#example2').jqRevolve({startPos: 50}); });
#example2 { width: 360px; margin: 10px 24px; border: 1px solid black; } #example2 .revolve-next, #example2 .revolve-prev { position: absolute; background-color: red; width: 25px; height: 100%; z-index: 10; } #example2 .revolve-next { right: 0; }
<div id="example2"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> jqRevolve - CLICK THE RED BLOCKS TO SCROLL THROUGH THIS CONTENT! AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ Viola! Fin. </div> </div>
$().ready(function(){ $('#example3 div.doNotCenter').jqRevolve({autoCenter: false}); $('#example3 div.doCenter').jqRevolve({autoCenter: true}); // default });
#example3 div.carousel { /* MUST be relative or absolute! */ /* Plugin will automatically set if not. */ /* See example 2 CSS */ position: relative; /* MUST be hidden! */ /* Plugin will automatically set if not. */ /* See example 2 CSS */ overflow: hidden; width: 520px; margin: 10px 24px; border: 1px solid black; } #example3 .revolve-content { /* MUST be relative or absolute! */ /* Plugin will automatically set if not. */ /* See example 2 CSS */ position: absolute; z-index: 5; } #example3 .revolve-next, #example3 .revolve-prev { position: absolute; background-color: blue; width: 25px; height: 100%; z-index: 10; } #example3 .revolve-next { right: 0; }
<div id="example3"> <div class="carousel doNotCenter"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> <img src="drink.jpg" /> </div> </div> <div class="carousel doCenter"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> <img src="drink.jpg" /> </div> </div> </div>
$().ready(function(){ $('#example4 div.doNotAutoSize').jqRevolve({autoSize: false}); $('#example4 div.doAutoSize').jqRevolve({autoSize: true}); // default });
#example4 div.carousel { width: 520px; margin: 10px 24px; border: 1px solid black; height: 20px; /* FIXED HEIGHT - LOOK! */ } #example4 .revolve-next, #example4 .revolve-prev { position: absolute; background-color: blue; width: 25px; height: 100%; z-index: 10; } #example4 .revolve-next { right: 0; }
<div id="example4"> <div class="carousel doNotAutoSize"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> <img src="drink.jpg" /> </div> </div> <div class="carousel doAutoSize"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> <img src="drink.jpg" /> </div> </div> </div>
$().ready(function(){ $('#example5').jqRevolve({maxSpeed: 25}); // slow });
#example5 { width: 520px; margin: 10px 24px; border: 1px solid black; } #example5 .revolve-content img { vertical-align: middle; } #example5 .revolve-next, #example5 .revolve-prev { position: absolute; background-color: green; width: 25px; height: 100%; z-index: 10; } #example5 .revolve-next { right: 0; }
<div id="example5"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> ><(({°> ><(({°> Start... <img src="drink.jpg" /> ><(({°> <img src="drink.jpg" /> Fin. ><(({°> ><(({°> </div> </div>
$().ready(function(){ $('#example6').jqRevolve({autoSize: true}); $('#updateExample6').click(function(){ // Grab random images from Flickr.com $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags="+getTag()+"&format=json&jsoncallback=?", function(data){ // create new content placeholder var newContent = ''; $.each(data.items, function(i,item){ newContent += '<img src="'+item.media.m+'" /> ' if ( i == 5 ) return false; }); // update example 6 carousel with newContent $('#example6').jqrRefresh(newContent); }); }); // random tags for Flickr Service var tags = ['kitten','goldfish','puppy'],i=0; function getTag(){ if(i == 3) i = 0; return tags[i++]; } });
#example6 { width: 600px; margin: 10px 24px; border: 1px solid black; } #example6 .revolve-next, #example6 .revolve-prev { position: absolute; background-color: yellow; width: 25px; height: 100%; z-index: 10; } #example6 .revolve-next { right: 0; } #updateExample6 { margin: 10px 60px; }
<div id="example6"> <div class="revolve-next"></div> <div class="revolve-prev"></div> <div class="revolve-content"> Populate Me! Click "Update Content"... </div> </div> <button id="updateExample6">Update Content</button>
$().ready(function(){ // initialize revolver $('#example7 div.revolve').jqRevolve({ next: $('#example7 div.next-button')[0], prev: $('#example7 div.prev-button')[0] }); // fill revolver content with random Flickr.com imagery $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=lemur&format=json&jsoncallback=?", function(data){ $.each(data.items, function(i,item){ $("<img/>").attr("src", item.media.m).appendTo("#example7 div.revolve-content"); if ( i == 7 ) return false; }); // refresh example 7's content [sizes to native height] $('#example7 div.revolve').jqrRefresh(); } ); });
/**** CLIP REGION *****/ #example7 div.revolve { position: relative; /* must be relative or absolute */ overflow: hidden; /* necessary for revolver behavior */ width: 300px; /* width of clip region */ } /* example7 specific styling [optional] */ #example7 div.revolve { clear: both; margin: 10px 30px; border: 1px solid #000; } #example7 div.revolve img { vertical-align: middle; } /**** SCROLL COMPONENTS *****/ #example7 div.button { float: left; text-align: center; color: #FFF; background: #000; cursor: pointer; margin: 10px 10px; padding: 0 30px; }
<div id="example7"> <div class="prev-button button">backward</div> <div class="next-button button">forward</div> <div class="revolve"> <div class="revolve-content"> Populated by <a href="http://flickr.com">Flickr.com</a> </div> </div> </div>
Previous Releases
All revisions of jqRevolve are available are available here.Contributing;