中断循环以启动 .click 事件,然后重新启动循环
我会告诉我的意思:
http://www.pixel3.it/marco/jslide /slide.html
我有这个基本的 .click 幻灯片,通过按下面的小方块可以在每个彩色框之间滑动。 '到现在为止一切都很好。
现在我真的想让彩色框永远循环,所以我使用这个代码:
$(document).ready(function runIt(){
$('#slider').animate({marginLeft: "0"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-900"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-1800"}, 500).delay(5000);
runIt;
});
它工作得很好,但我不能再手动切换框。
我想知道是否可以混合这两段代码:
$('#slider').animate({marginLeft: "0"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-900"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-1800"}, 500).delay(5000);
runIt;
});
$('a#but1').click(function(){
$('#slider').animate({marginLeft: "0"}, 500)
});
$('a#but2').click(function(){
$('#slider').animate({marginLeft: "-900"}, 500)
});
$('a#but3').click(function(){
$('#slider').animate({marginLeft: "-1800"}, 500)
});
});
使框循环,直到我按下其中一个彩色方块,该方块执行其 .click 事件,然后重新启动循环。
编辑:我尝试将 .stop() 添加到每个 .click 事件,但不起作用。
EDIT2(几乎解决了):经过一番搜索并幸运地找到了这个插件: http://flesler.blogspot.com/2007/10/jqueryscrollto.html 我认为这也可以帮助我。
现在仅使用该循环插件,我的代码是:
$('#slider').cycle({fx: 'scrollLeft',
speed: 500,
timeout: 5000});
$('a#but1').click(function() {
$('#slider').cycle(0);
return false;
});
$('a#but2').click(function() {
$('#slider').cycle(1);
return false;
});
$('a#but3').click(function() {
$('#slider').cycle(2);
return false;
});
});
遗憾的是,该插件不会滚动所有帧,而只会滚动当前帧和下一个帧。 我的意思是,如果当幻灯片位于第一个框上时按第三个方块,则在动画期间不考虑第二个框。希望我是对的,因为我已经阅读了循环插件文档,但没有找到任何命令来执行此操作。
I'll tell what I mean:
http://www.pixel3.it/marco/jslide/slide.html
I have this basic .click slideshow that slides trough every coloured box by pressing on the little squares below.
'Till now everything is good.
Now I really want to make the coloured boxes loop forever so I use this code:
$(document).ready(function runIt(){
$('#slider').animate({marginLeft: "0"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-900"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-1800"}, 500).delay(5000);
runIt;
});
It works good but I can't anymore switch through the boxes manually.
I was wondering if was possible to mix these two piece of code:
$('#slider').animate({marginLeft: "0"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-900"}, 500).delay(5000);
$('#slider').animate({marginLeft: "-1800"}, 500).delay(5000);
runIt;
});
$('a#but1').click(function(){
$('#slider').animate({marginLeft: "0"}, 500)
});
$('a#but2').click(function(){
$('#slider').animate({marginLeft: "-900"}, 500)
});
$('a#but3').click(function(){
$('#slider').animate({marginLeft: "-1800"}, 500)
});
});
making the boxes loop until i press one of the coloured squares, which does its .click event, and then restart the loop.
EDIT: I've tried to add .stop() to every .click event but doesn't work.
EDIT2 (almost solved): After a little search and with some luck I've found this plugin: http://flesler.blogspot.com/2007/10/jqueryscrollto.html I think this can help me aswell.
Right now using only that cycle plugin my code is:
$('#slider').cycle({fx: 'scrollLeft',
speed: 500,
timeout: 5000});
$('a#but1').click(function() {
$('#slider').cycle(0);
return false;
});
$('a#but2').click(function() {
$('#slider').cycle(1);
return false;
});
$('a#but3').click(function() {
$('#slider').cycle(2);
return false;
});
});
Sadly this plugin doesn't scroll trought ALL the frames but only the current and the next to come.
I mean if I press the 3rd square when the slideshow is on the 1st box, during the animation the 2nd box is not considered. Hoping I'm right, because I've read the cycle plugin documentation and I didn't find any command to do so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jquery 幻灯片(http://jquery.malsup.com/cycle/)之类的东西可能会更好地帮助您处理过渡。
像这样的循环可能永远不允许事件管理发生,并且可能是您的点击事件似乎没有触发的原因。他们可能正在等待循环完成才能对其进行处理。因此,实际上您已经创建了一个无限循环,并且您的事件正在排队等待。
You maybe better served by something like jquery slideshow (http://jquery.malsup.com/cycle/)to deal with your transitions.
A loop like that might never allow for event management to occur, and might be responsible for why your click events do not seem to trigger. They may be waiting for the loop to complete before they would be handled. So in effect you have created an infinite loop and your events are qued waiting.