Skip to content

Instantly share code, notes, and snippets.

@PerpetualBeta
Created October 27, 2012 22:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PerpetualBeta/3966765 to your computer and use it in GitHub Desktop.
Save PerpetualBeta/3966765 to your computer and use it in GitHub Desktop.
Compact, vertical, infinite ticker/scroller. Pauses on "mouseenter" event.
(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);
@PerpetualBeta
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment