Created
October 27, 2012 22:54
-
-
Save PerpetualBeta/3966765 to your computer and use it in GitHub Desktop.
Compact, vertical, infinite ticker/scroller. Pauses on "mouseenter" event.
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
(function ($) { | |
$.fn.ticker = function (options) { | |
var defaults = { | |
speed: 1000, | |
pause: 3000, | |
p: false | |
}; | |
options = $.extend(defaults, options); | |
scroller = function (obj2, height, options) { | |
if (options.p) return; | |
var obj = obj2.children('ul'); | |
var clone = obj.children('li:first').clone(true); | |
obj.animate({ top: '-=' + height + 'px' }, options.speed, function () { | |
$(this).children('li:first').remove(); | |
$(this).css('top', '0px'); | |
}); | |
obj.children('li:first').fadeOut(options.speed); | |
clone.appendTo(obj); | |
}; | |
return this.each(function () { | |
var obj = $(this); | |
var totalHeight = 0; | |
obj.css({ overflow: 'hidden', position: 'relative' }).children('ul').css({ position: 'absolute' }); | |
obj.children('ul').children('li').each(function () { | |
totalHeight += $(this).outerHeight(); | |
}); | |
obj.height(totalHeight); | |
var interval = setInterval(function () { | |
scroller(obj, obj.children('ul').children('li:first').outerHeight(), options); | |
}, options.pause); | |
obj.bind('mouseenter', function () { | |
options.p = true; | |
}).bind('mouseleave', function () { | |
options.p = false; | |
}); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo: http://darkblue.sdf.org/lab/ticker/ticker.php