I use this little code snippet for a jquery news ticker:
var speed = 5;
var items, scroller = $('#scroller');
var width = 0;
scroller.children().each(function(){
width += $(this).outerWidth(true);
});
scroller.css('width', width);
scroll();
function scroll(){
items = scroller.children();
var scrollWidth = items.eq(0).outerWidth();
scroller.animate({'left' : 0 - scrollWidth}, scrollWidth * 100 / speed, 'linear', changeFirst);
}
function changeFirst(){
scroller.append(items.eq(0).remove()).css('left', 0);
scroll();
}
I try to pause the script when mouseover.
Using stop() function, it works but it loses speed every time I pass my mouse over.
I know their is something to do with width / distance / speed but I'm unable to correct it.
Here is the full script: http://codepen.io/anon/pen/wBayyz
Thank You.
The problem was when you were restarting the scrolling you need to take into consideration how much has been scrolled already, like I've done here.
This should be what you're looking for,