Jquery 淡入淡出,带有暂停或延迟
如果有以下代码,但在淡入和淡出后我无法暂停:
$(document).ready(function () {
$('#signupButtonFlash').each(function (i) {
// Get the image, set the count and an interval.
var img = $('.bttn_play');
img[0].$count = 0;
img[0].$interval = setInterval(function () {
// Animate the opacity over .2 seconds
img.animate({
opacity: .3
}, 400, function ()
{
// When finished, animate it back to solid.
img.animate({
opacity: 1
}, 400);
});
// Clear the interval once we've reached 1000.
if (++img[0].$count >= 1000) {
clearInterval(img[0].$interval);
}
}, 1000);
});
});
If have the following code but i cant get a pause AFTER ever fade in and fade out:
$(document).ready(function () {
$('#signupButtonFlash').each(function (i) {
// Get the image, set the count and an interval.
var img = $('.bttn_play');
img[0].$count = 0;
img[0].$interval = setInterval(function () {
// Animate the opacity over .2 seconds
img.animate({
opacity: .3
}, 400, function ()
{
// When finished, animate it back to solid.
img.animate({
opacity: 1
}, 400);
});
// Clear the interval once we've reached 1000.
if (++img[0].$count >= 1000) {
clearInterval(img[0].$interval);
}
}, 1000);
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这样就达到了你想要的效果。您也可以按照其他人的建议使用延迟,但我担心上一个动画仍在运行时的间隔触发。相反,此代码每隔 1000 毫秒触发一次间隔,并每隔一段时间淡入和淡出,超过 200 毫秒。
请注意,我已经移动了
++
!This achieves what you want. You could also use
delay
as suggested by others, but I'd be worried about the interval triggering while the previous animation is still running. This code instead trigger the interval at (e.g.) every 1000 ms and fades in and out every other time, oves 200 ms.Please note that I've moved the
++
!您的代码可以显着减少:
在这里工作fiddle可用:http://jsfiddle.net /BEMSD/89/
Your code can be reduced significantly:
Working fiddle available here: http://jsfiddle.net/BEMSD/89/
这对您的代码并不完全有帮助,但也许您应该研究 jQuery Cycle 插件,因为听起来您想以幻灯片方式循环浏览一堆图像/内容,并且能够暂停/播放。
This doesn't exactly help with your code, but maybe you should look into the the jQuery Cycle plugin, because it sounds like you want to cycle through a bunch of images/content in a slideshow manner with the ability to pause/play.