鼠标悬停时暂停动画
我正在使用 jQuery 脚本淡入和淡出一堆 ....
标签,效果很好,但我需要动画在鼠标悬停时暂停并在鼠标悬停时恢复鼠标移开!我可以在脚本中添加任何方法来处理这个问题吗?
$(function() {
function InOut(elem) {
elem.delay()
.fadeIn(600)
.delay(5000)
.fadeOut(600,
function() {
if (elem.next().length > 0) {
InOut(elem.next());
} else {
InOut(elem.siblings(':first'));
}
}
);
}
$('#anidiv p').hide();
InOut($('#anidiv p:first'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="anidiv">
<p>Pause jquery animation on mouseover...1</p>
<p>Pause jquery animation on mouseover...2</p>
<p>Pause jquery animation on mouseover...3</p>
<p>Pause jquery animation on mouseover...4</p>
</div>
I am using a jQuery script to fade in and out a bunch of <p>....</p>
tags which works fine but I need the animation to pause on mouseover and resume on mouse out! Is there any method I can add to the script to handle this?
$(function() {
function InOut(elem) {
elem.delay()
.fadeIn(600)
.delay(5000)
.fadeOut(600,
function() {
if (elem.next().length > 0) {
InOut(elem.next());
} else {
InOut(elem.siblings(':first'));
}
}
);
}
$('#anidiv p').hide();
InOut($('#anidiv p:first'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="anidiv">
<p>Pause jquery animation on mouseover...1</p>
<p>Pause jquery animation on mouseover...2</p>
<p>Pause jquery animation on mouseover...3</p>
<p>Pause jquery animation on mouseover...4</p>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以放置一些内容,而不是检查可见性以继续
类或任何适合您区分当前显示元素与其他元素的内容。
鼠标悬停时停止动画
Instead of checking the visibility to continue you can put some
class or anything that suit you to distinguish the current show element from the others.
stop animation on mouseover
这个插件将为 jQuery 提供暂停和恢复单个动画的功能。对于暂停一系列动画,zdrsh 的答案应该很好。
This plugin will give jQuery the functionality to pause and resume individual animations. For pausing the series of animations, zdrsh's answer should do fine.