Javascript jQuery在不同的函数上等待操作完成
我已经创建了一个新闻提要。馈电每2秒切换一次。您也可以手动向左/向右切换,或从底部的正方形中单击面板。使用jQueryUISlide可以停止幻灯片之间的切换Javascript jQuery在不同的函数上等待操作完成,javascript,jquery,animation,Javascript,Jquery,Animation,我已经创建了一个新闻提要。馈电每2秒切换一次。您也可以手动向左/向右切换,或从底部的正方形中单击面板。使用jQueryUISlide可以停止幻灯片之间的切换 现在,如果你在一个幻灯片的中间,点击左/右/正方形,那么另一个幻灯片出现在现有的,仍然在滑动的上面,整个系统都被搞乱了。 如果滑动/切换已在进行中,如何防止发生其他操作 这是我的代码: $(document).ready(function(){ newsfeedTimer = setInterval(newsfeed, displa
现在,如果你在一个幻灯片的中间,点击左/右/正方形,那么另一个幻灯片出现在现有的,仍然在滑动的上面,整个系统都被搞乱了。
如果滑动/切换已在进行中,如何防止发生其他操作 这是我的代码:$(document).ready(function(){
newsfeedTimer = setInterval(newsfeed, displayDuration);
// Manual change of feed (LEFT)
$('#newsfeeds_wrapper > .left').click(function(event){
event.stopPropagation();
feedLeft();
clearInterval(newsfeedTimer);
newsfeedTimer = setInterval(newsfeed, displayDuration);
});
// Very similar code for feed right
// Ignore the other method of switching (if it works for above, I can implement it for this one)
});
function newsfeed() {
feedRight();
}
// Feed to the Right
// jump is used to jump multiple newsfeed instead of one at a time
function feedRight(jump)
{
jump = typeof jump !== 'undefined' ? jump : 1;
var current = $('.newsfeed:first');
var next = $('.newsfeed:nth(' + jump + ')');
current.hide('slide',{duration: transitionDuration}, function(){
// Append as many needed
for( var i = 0; i < jump; i++ ) {
$('.newsfeed:first').appendTo('#newsfeeds');
}
next.show('slide',{direction : 'right' , duration: transitionDuration});
}
$(文档).ready(函数(){
newsfeedTimer=设置间隔(newsfeed,displayDuration);
//手动更换进料(左)
$('#newsfeeds\u wrapper>.left')。单击(函数(事件){
event.stopPropagation();
feedLeft();
clearInterval(newsfeedTimer);
newsfeedTimer=设置间隔(newsfeed,displayDuration);
});
//feed right的代码非常相似
//忽略另一种切换方法(如果对上面的方法有效,我可以为这个方法实现)
});
函数newsfeed(){
feedRight();
}
//向右馈送
//跳转用于跳转多个新闻源,而不是一次跳转一个新闻源
功能feedRight(跳转)
{
跳转=跳转类型!=“未定义”?跳转:1;
当前变量=$('.newsfeed:first');
var next=$('.newsfeed:nth('+jump+');
hide('slide',{duration:transitionDuration},function(){
//追加所需数量
对于(变量i=0;i
我不想停止()一个动画!如果有动画发生,我想禁用更改幻灯片!!在看不到全部代码的情况下,我在这里向自己开枪。但我会选择这个方向。您还可以有两个功能,一个用于绑定,另一个用于解除绑定。启动动画时,您可以解除左/右键的绑定停止时,您可以绑定。或者,设置一个全局变量…ala
var config = {'inProgress': false};
$('#newsfeeds_wrapper > .left').click(function(event){
if(!config.inProgress){
event.stopPropagation();
feedLeft();
clearInterval(newsfeedTimer);
newsfeedTimer = setInterval(newsfeed, displayDuration);
}
});
在你的动画功能中。似乎当你剪切/粘贴时,一些代码丢失了,所以让我们假设一些动画
当您输入动画功能时,设置config.inProgress=true
function feedRight(jump)
{
config.inProgress = true;
// removed your code, but just using for simplicity sake
// added a callback
next.show('slide',{direction : 'right' , duration: transitionDuration},
function() {
// Animation complete. Set inProgress to false
config.inProgress = false;
});
)
}
如果没有任何类型的代码,您可以查看jQuery UI API,了解如何停止您正在谈论的任何内容。或者,如果是动画,请查看jQuery的
stop()
方法