Team:UCLA/Aal/javascripttemplate

From 2014.igem.org

(Difference between revisions)
Line 40: Line 40:
$("#slides").rotator(55, 1000, 'img');
$("#slides").rotator(55, 1000, 'img');
});
});
 +
(function( $ ){
 +
$.fn.rotator = function(delay, time, child){
 +
//set curImage val
 +
var currImg = 0;
 +
var currIt = true;
 +
//set array of images
 +
var ss = $(this).children(child);
 +
var ssize = ss.size();
 +
var startTime = new Date().getTime();
 +
var interval = setInterval(function() {
 +
if(currIt){
 +
$(ss[currImg]).css('opacity','1');
 +
currIt = !currIt;
 +
}else if (!currIt){
 +
                $(ss[currImg]).css('opacity','0');
 +
$(ss[currImg+1]).css('opacity','1');
 +
currIt = !currIt;
 +
currImg++;
 +
}
 +
//reset
 +
if(currImg >= ssize){
 +
currImg = 0;
 +
$(ss[currImg]).css('opacity','1');
 +
}
 +
if(new Date().getTime() - startTime > time){
 +
clearInterval(interval);
 +
return;
 +
}
 +
}, delay);
 +
return this;
 +
};
 +
})(jQuery);
</script>
</script>
</html>
</html>

Revision as of 22:32, 2 September 2014