我的垂直自动滚动似乎在某些时候不规律地停止,我想要一个平滑的滚动。其次,我希望垂直滚动自动重置(几乎无限循环或暗示它永无止境,而不仅仅是跳跃)。我将如何实现这一目标?到目前为止,这是我的代码:http: //jsfiddle.net/8KjX8/78/。
HTML
<div id="wrapper">
<ul>
<li><div id='activity_date'>06/11/2012</div></li>
<li><div id='activity_date'>06/11/2012</div></li>
<li><div id='activity_date'>06/11/2012</div></li>
<li><div id='activity_date'>06/11/2012</div></li>
<li><div id='activity_date'>06/11/2012</div></li>
<li><div id='activity_date'>06/11/2012</div></li>
</ul>
</div>
CSS
#activity_date {
background-color: #cc0066;
color: #FFF;
width: 80px;
}
#wrapper {
height: 240px;
overflow: hidden;
}
#wrapper ul {
position: relative;
list-style-type: none;
}
#wrapper li {
height: 30px;
line-height: 12px;
list-style-type: none;
}
JS
(function(){
var i = 0;
function Scroll() {
i++;
if (i < $('li').length) { // scroll down till we are at the last item
$('ul').animate({top:'-=30'+'px'}, 1000);
}
}
$(document).ready(function() {
var timeOut;
$('ul').hover(
function(e) { // on hover in, stop the animation
clearTimeout(timeOut);
},
function(e) { // on hover out, continue
timeOut = setInterval(Scroll, 1000);
}
);
timeOut = setInterval(Scroll, 1000); // start the animation at document load
});
})();
提前致谢!