Skip to content

Instantly share code, notes, and snippets.

@JacobBennett
Last active December 25, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobBennett/6977513 to your computer and use it in GitHub Desktop.
Save JacobBennett/6977513 to your computer and use it in GitHub Desktop.
The simplest jquery rotator I could come up with
<!-- ROTATOR HTML -->
<div class="rotator-container">
<img src="images/preview/1.jpg" class="active"/>
<img src="images/preview/2.jpg" />
<img src="images/preview/3.jpg" />
</div>
$(document).ready(function() {
var images = $('.rotator-container img');
(function rotateImages() {
var no_of_images = images.length -1,
i = 1,
j = 2;
function rotator() {
if (i === 3) {i = 0;}
$(images[i]).addClass('active');
$(images[j]).removeClass('active');
j=i;
i++;
}
setInterval(rotator, 3500);
})();
$('a.grouped-elements').fancybox();
});
.rotator-container {width: 343px; position: relative; margin: 0 auto;}
.rotator-container img {
opacity: 0;
position: absolute;
z-index: 3;
top: 16px;
left: -1px;
-webkit-transition: .5s;
-o-transition: .5s;
transition: .5s;
}
.rotator-container img.active {opacity: 1;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment