动画在悬停时停止,在鼠标离开时开始,但不能再次悬停以重复停止动画
Animation stop on hover, begin on mouseout but can't hover again to repeat stop animation
在旋转木马上工作,我有动画和div包装工作,但是我想添加在悬停时停止旋转木马并在鼠标离开时重新启动动画的能力,但是它只工作一次。悬停停止动画,mouseout再次启动,但如果我再次悬停,它不会停止。
var roundabout = setInterval(function(){
spin()
}, 3000);
function spin(){
var kerosene = document.getElementById('carousel-frame-holder');
var s = kerosene.offsetLeft;
if (s >= -1700 ){
$("#carousel-frame-holder").animate({left: (s - 600 +'px')});
}
else{
$("#carousel-frame-holder").animate({left: (s + 1800 +'px')});
}
// interruption
$("#carousel-view-window" ).hover(function() {
$("#carousel-frame-holder").stop();
clearInterval(roundabout);
});
$("#carousel-view-window" ).mouseout(function() {
setInterval(function(){spin()}, 3000);
});
};
//wrap
$('#nav-left').click(function(){
var kerosene = document.getElementById('carousel-frame-holder');
var s = kerosene.offsetLeft;
if (s <= -1 ){
$("#carousel-frame-holder").animate({left: (s + 600 +'px')});
}
else {$("#carousel-frame-holder").animate({left: (s - 1800 +'px')});}
});
$('#nav-right').click(function(){
var kerosene = document.getElementById('carousel-frame-holder');
var s = kerosene.offsetLeft;
if (s >= -1700 ){
$("#carousel-frame-holder").animate({left: (s - 600 +'px')});
}
else {$("#carousel-frame-holder").animate({left: (s + 1800 +'px')});}
});
问题似乎是您订阅的事件不正确。jQuery hover处理mouseenter
和mouseleave
事件的方式如下:
$('#carousel-view-window').hover(function(){
//Stop Animation here
$("#carousel-frame-holder").stop();
clearInterval(roundabout);
}, function(){
//Restart Animation here
roundabout = setInterval(function(){spin()}, 3000);
});
您不需要单独订阅mouseout
事件。
确保您将间隔id存储在mouseleave
处理程序中,以便您可以再次清除它。
相关文章:
- jQuery悬停动画只在其他类似元素中的一个元素上
- 如何动画删除悬停后的背景
- 如何在鼠标悬停时停止动画
- jQuery透明图像描述鼠标悬停时的幻灯片动画
- 悬停在动画文本上后,文本淡入淡出不会返回
- 在悬停Jquery/cs3时通过翻转动画更改文本
- 如何在 jquery 中克服此问题以获得动画悬停效果
- 悬停不起作用时对不透明度更改进行动画处理
- 我只想在卡片悬停上悬停动画,而不是在身体上
- 为什么在使用JQuery时,当我悬停时,没有流畅的动画
- 使用 javascript 在鼠标悬停时停止动画
- jQuery mouseout动画仅在第二次悬停后启动
- 用这个jQuery动画菜单悬停超链接
- 如何使用if hasClass条件禁用jQuery mouseleave事件?//悬停动画
- 使用Javascript悬停的CSS动画
- Chrome动画CSS3三维立方体与悬停状态问题
- d3将鼠标悬停在表格上时,制作图表动画
- CSS动画悬停在外
- 拉斐尔饼图动画悬停
- 旋转动画悬停,但同时移动鼠标悬停->取消