Tip: Click lines to highlight, hold ctrl/cmd to multi-select
Block rotator (10-Jul @ 16:28)
Usage: $('blockquote').rotate(2000); // in milliseconds
Syntax Highlighted Code
- $.fn.rotate = function (delay) {
- var rotators = this,
- n = this.length,
- current = 0,
- timer = null;
- rotators.hide().eq(current).show();
- timer = setInterval(function () {
- current++;
- if (current == n) current = 0;
- rotators.hide().eq(current).show();
- }, delay);
- return rotators;
- };
Plain Code
$.fn.rotate = function (delay) {
var rotators = this,
n = this.length,
current = 0,
timer = null;
rotators.hide().eq(current).show();
timer = setInterval(function () {
current++;
if (current == n) current = 0;
rotators.hide().eq(current).show();
}, delay);
return rotators;
};