使用 Jquery Cycle 暂停/恢复动画
更新
我已经让它在一定程度上工作了,我不知道为什么,但是一旦使用循环后的回调调用动画,似乎与之交互的唯一方法就是使用jquery 的 .stop 方法。
如果有人能为我阐明这一点,那就太棒了。
谢谢!
下面的原始问题
我正在使用这个暂停/恢复插件:http://tobia. github.com/Pause/
我已经用一个简单的动画对其进行了测试,效果很好。
我的问题是我试图在 Jquery Cycle 中使用它,但它根本不起作用。
目前,我有一个非常标准的自行车滑块,它有一个导航。每个导航项都有一个计时器栏,其起始尺寸为 320 像素,并根据每张幻灯片的长度以动画方式降至 0。
我正在尝试弄清楚如何将暂停插件与此结合起来,这样当我将鼠标悬停在幻灯片上时,计时器栏动画就会暂停,并在鼠标移出时恢复。
有人可以帮我吗?
提前致谢。
这是我的代码:
HTML(仅显示一张幻灯片以保持代码最少)
<div id="slider_images">
<div class="slideshow">
<div><img src="img_path" title="Slider Span" alt="Slider Span"/> <div class="slider_buttons"><a href="/index.php?p=about-us" class="learn-more-btn">Learn More</a> <a href="#" class="send-me-information fancyNews">Send Me Information</a></div> </div>
</div>
</div>
<ul id="multiNav"><li><a class="slide0" href="#">Why CBHM?</a>
<p>
Why You Should Choose Us
</p>
<div id="progress-bar"></div>
<div id="progressbar">
<div id="progressvalue"></div>
</div>
</li>
</ul>
JS
$('.slideshow').cycle({
fx: 'fade',
timeout: 7000,
pager: '#multiNav',
after: onAfter,
before: before,
pagerAnchorBuilder: function(idx, slide) {
return '#multiNav li:eq(' + (idx) + ') a';
}
});
function before() {
$('.activeSlide #progress-bar').css({ width: "0%" });
}
function onAfter() {
$('.activeSlide #progress-bar').animate({ width: "280px"}, 0, function() {
$('.activeSlide #progress-bar').animate({ width: "0px" }, 6200);
});
}
$("#container_Slider").hover(function() {
$('#progress-bar').pause();
}, function() {
$('#progress-bar').resume();
});
UPDATE
I've got it working to an extent, i'm not sure why but once an animation is called using the after callback with cycle, it seems like the only way to interact with it is by using jquery's .stop method.
If anyone could shed some light into this for me, that'd be awesome.
Thanks!
ORIGINAL QUESTION BELOW
I'm using this Pause/Resume plugin: http://tobia.github.com/Pause/
I have tested it out with a simple animation and it works great.
My issue is that i'm trying to use it within Jquery Cycle, and it's not working at all.
Currently, I have a pretty standard cycle slider, which has a navigation. Each navigation item has a timer bar, which starts at 320px, and animates down to 0 based on the length of each slide.
I'm trying to figure out how to incorporate that pause plugin with this, so the timer bar animation will pause when I hover over the slideshow, and resume when I mouse out.
Can anyone help me out here?
Thanks in advance.
Here's my code:
HTML (only showing one slide to keep code to minimum)
<div id="slider_images">
<div class="slideshow">
<div><img src="img_path" title="Slider Span" alt="Slider Span"/> <div class="slider_buttons"><a href="/index.php?p=about-us" class="learn-more-btn">Learn More</a> <a href="#" class="send-me-information fancyNews">Send Me Information</a></div> </div>
</div>
</div>
<ul id="multiNav"><li><a class="slide0" href="#">Why CBHM?</a>
<p>
Why You Should Choose Us
</p>
<div id="progress-bar"></div>
<div id="progressbar">
<div id="progressvalue"></div>
</div>
</li>
</ul>
JS
$('.slideshow').cycle({
fx: 'fade',
timeout: 7000,
pager: '#multiNav',
after: onAfter,
before: before,
pagerAnchorBuilder: function(idx, slide) {
return '#multiNav li:eq(' + (idx) + ') a';
}
});
function before() {
$('.activeSlide #progress-bar').css({ width: "0%" });
}
function onAfter() {
$('.activeSlide #progress-bar').animate({ width: "280px"}, 0, function() {
$('.activeSlide #progress-bar').animate({ width: "0px" }, 6200);
});
}
$("#container_Slider").hover(function() {
$('#progress-bar').pause();
}, function() {
$('#progress-bar').resume();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有点晚了,但您可以使用animation-play-state 暂停动画。结合jquery悬停你会得到这样的东西......
This is a little late, but you can pause an animation using animation-play-state. Combined with jquery hover you get something like this...
跳过暂停插件 - jQuery Cycle 内置暂停/恢复功能。
Skip the pause plugin -- jQuery Cycle has pause/resume functionality built-in.