Last active
December 20, 2015 01:29
-
-
Save schmidtsonian/6049520 to your computer and use it in GitHub Desktop.
Animate sequence images
This file contains hidden or 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
/* | |
* params: array | |
* params.interval int, milisegundos para intervalos | |
* params.element DOM, ejemplo: $('.contenedor img' ) | |
* params.increment bool, true = +1 | |
* params.onComplete | |
*/ | |
function animateSequence( params ){ | |
var index = 0; | |
var count = 0; | |
var pictureCount = params.element.length; | |
var indexOffset = 1 | |
if(params.increment == true){ | |
indexOffset = -1; | |
index = pictureCount-1; | |
} | |
var interval = setInterval( function(){ | |
params.element.css({"display": "none"}); | |
params.element.eq(index).css({"display": "block"}); | |
index = index + indexOffset; | |
count++; | |
if( count == pictureCount ){ | |
index = pictureCount; | |
clearInterval(interval); | |
if(params.onComplete){ | |
params.onComplete(); | |
} | |
if(params.isDisplayLast == false){ | |
params.element.css({"display": "none"}); | |
} | |
} | |
}, params.interval ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment