Last active
December 25, 2015 12:38
-
-
Save JacobBennett/6977513 to your computer and use it in GitHub Desktop.
The simplest jquery rotator I could come up with
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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