这是我的jQuery
$('#samsungShine').mouseover(function () {
$('#samsungShineImage').animate({
"margin-left": "304px"
}, 700);
}).mouseout(function () {
$('#samsungShineImage').css("margin-left", "-304px");
});
Run Code Online (Sandbox Code Playgroud)
当我鼠标移动时,它工作得非常好,当我鼠标移除时,它没有重置,它重新播放鼠标悬停...这里是问题的小提示,所以你可以看到我的意思:
尝试mouseenter而mouseleave不是:http://jsfiddle.net/2tujd/11/
$('#samsungShine').mouseenter(function () {
$('#samsungShineImage').animate({
"margin-left": "304px"
}, 700);
}).mouseleave(function () {
$('#samsungShineImage').stop().css("margin-left", "-304px");
});
Run Code Online (Sandbox Code Playgroud)
在jQuery网站上,它说关于使用mouseout和simliarly mouseover:
由于事件冒泡,此事件类型可能会导致许多麻烦.例如,当鼠标指针在此示例中移出Inner元素时,将向其发送mouseout事件,然后逐渐向外传递.这可以在不合适的时间触发绑定的mouseout处理程序.
编辑:添加.stop()内部mouseleave以确保在设置之前停止任何当前动画margin-left.
尝试一下,stop也使用:
$('#samsungShine').mouseenter(function() {
$('#samsungShineImage').animate({"margin-left":"304px"}, 700);
}).mouseleave(function(){
$('#samsungShineImage').stop().css("margin-left", "-304px");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
463 次 |
| 最近记录: |