我试图创建一个动画滑块,来回显示图像和动画,除非鼠标悬停,它暂停鼠标悬停,需要继续鼠标离开。我创造了这个,但当鼠标离开时有一些愚蠢的问题,动画只会完成一个循环。一些帮助。 下面是代码:动画滑块不继续鼠标离开
jQuery.fn.makeScroller = function(options){
var defaults = {
hoverStop : true
};
var options = jQuery.extend(defaults, options);
obj = this;
var scrollWrapWidth = 0;
obj.children().each(function(){ scrollWrapWidth += $(this).width(); });
scrollWrapper = jQuery('<div/>',{class:"scrollWrapper", style:"width:"+scrollWrapWidth+"px"});
obj.children().wrapAll(scrollWrapper);
function animateThis(obj, dist, time){
obj.animate({marginLeft: dist}, {
duration:time,
complete:function(){
obj.animate({marginLeft: "0"}, {
duration:time,
complete:function(){
animateThis(obj, dist, time);
}
})
}
});
obj.hover(function(){
obj.stop(true);
}, function(){
animateThis(obj, dist, time);
});
};
widthDiff = (scrollWrapWidth - obj.width()) * -1;
animateThis(obj.children(".scrollWrapper"), widthDiff, 3000);
}
jQuery(document).ready(function(){
id = ".myScroller";
jQuery(id).makeScroller();
});
这里是我创造了你发现问题的小提琴链接 - http://jsfiddle.net/cruising2hell/YvNR6/4/
感谢