Skip to content

Instantly share code, notes, and snippets.

@yoko
Created October 15, 2009 01:41
Show Gist options
  • Save yoko/210565 to your computer and use it in GitHub Desktop.
Save yoko/210565 to your computer and use it in GitHub Desktop.
(function($) {
var defaultOptions = {
speed: 0.15
};
$.fn.ticker = function(options) {
options = $.extend(defaultOptions, options);
return this.each(function() {
var ul = $(this);
var container_width = ul.parent().width();
var width = 0;
$('li', this).each(function() {
width += $(this).width();
});
width += container_width;
ul.css({
width : width,
marginLeft: container_width
});
(function loop() {
ul.animate(
{ marginLeft: width * -1 },
width / options.speed,
'linear',
function() {
ul.css('margin-left', container_width);
loop();
}
);
})();
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment