Hey guys,
I found code posted by a user on here for a seamless jQuery marquee/ticker. I've modified it to start and stop when scrolled over/scrolled out of, but it often lags once the user scrolls out. It never completely stops, but the speed at which the ticker scrolls is sometimes 1/10 of its original speed. I've sped it up so it's easier to see this lagging. Anyway, if someone has any idea of how to fix this, I would greatly appreciate it.
jQuery
$(function() {
var marquee = $("#scroller");
marquee.css({"overflow": "hidden", "width": "100%"});
// wrap "My Text" with a span (IE doesn't like divs inline-block)
marquee.wrapInner("<span>");
marquee.find("span").css({ "width": "49%", "display": "inline-block", "text-align":"center", "padding-right":"1%" });
marquee.append(marquee.find("span").clone()); // now there are two spans with "My Text"
marquee.wrapInner("<div class='scrolling'>");
marquee.find("div").css("width", "200%");
var reset = function() {
$(this).css({"margin-left":"0%"});
$(this).animate({ "margin-left": "-100%" }, 500, 'linear', reset);
};
reset.call(marquee.find("div"));
marquee.find("div").bind({
mouseenter: function () {
$(this).stop();
if($(this).css("margin-left") == "-"+$("#scroller").width() + "px") $(this).css("margin-left", "0%");
},
mouseleave: function() {
$(this).stop().animate({ "margin-left": "-100%" }, 500, 'linear', reset);
}
});
});
HTML
<div id="scroller">
Lorem ipsum dolor sit amet. — <a href="#">Username</a>
Lorem ipsum dolor sit amet. — <a href="#">Username</a>
Lorem ipsum. — <a href="#">Username</a>
Lorem ipsum dolor sit amet. — <a href="#">Username</a>
Lorem ipsum dolor sit amet. — <a href="#">Username</a>
Lorem ipsum dolor sit amet. — <a href="#">Username</a>
Lorem ipsum. — <a href="#">Username</a>
Lorem ipsum dolor sit amet. — <a href="#">Username</a>
</div>
Thanks,
Greg