【发布时间】:2014-11-26 14:45:06
【问题描述】:
我将这个小代码 sn-p 用于 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
谢谢。
【问题讨论】:
-
检查我的答案以获得仅 CSS 的解决方案。
标签: javascript jquery mouseover ticker news-ticker