如何在鼠标悬停时停止动画并在鼠标悬停时重新启动我尝试了以下代码,但它不起作用:
var containerheight = 0;
var numbercount = 0;
var liheight;
var index = 1;
function callticker() {
jQuery("#news-container1 ul").animate({
"margin-top": (-1) * (liheight * index)
}
, 2500);
if (index != numbercount - 1) {
index = index + 1;
}
else {
index = 0;
}
timer = setTimeout("callticker()", 3600);
}
jQuery(document).ready(function() {
var timer=null;
jQuery('#news-container1').height("42px");
jQuery('#news-container1').css("overflow","hidden");
numbercount = jQuery("#news-container1 ul li").size();
liheight = jQuery("#news-container1 ul li").outerHeight();
containerheight = jQuery("#news-container1 ul li").outerHeight() * numbercount;
jQuery("#news-container1 ul").css("height", containerheight);
timer = setTimeout("callticker()", 3600);
jQuery("#news-container1 ul").mouseover(function(){
clearTimeout(timer );
}).mouseout(function(){
timer = setTimeout("callticker()", 3600);
})
});
JSfiddle 链接http://jsfiddle.net/3Y3qq/
谢谢,