我将这个小代码片段用于 jquery 新闻自动收报机:
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();
}
我尝试在鼠标悬停时暂停脚本。
使用 stop() 函数,它可以工作,但每次我通过鼠标时它都会失去速度。
我知道它们与宽度/距离/速度有关,但我无法纠正。
这是完整的脚本:http ://codepen.io/anon/pen/wBayyz
谢谢你。