简体   繁体   English

两个淡入淡出切换效果之间的jQuery延迟

[英]Jquery delay between two fade toggle effects

I am showing and displaying two divs using Jquery 我正在使用Jquery显示和显示两个div

The code is 该代码是

var show_hide = function () {
    $("#extravagents_label").fadeToggle(function () {
        $("#liquid.liquidContanier").fadeToggle().delay(1500);
    });
}

setInterval(show_hide, 1500);

but there is problem. 但是有问题 it is not doing the job properly. 它做得不好。 It should display the other div when one is completely hidden. 当一个完全隐藏时,它应该显示另一个div。 Kindly visit 203.81.193.2/jsvt/ . 请访问203.81.193.2/jsvt/ There are the icons and the text under the main slider that is displaying and hiding. 在显示和隐藏的主滑块下有图标和文本。

You should be careful with timings and setInterval it can mess things up pretty bad. 您应该注意时序和setInterval它会使事情变得很糟糕。

If timings are the problem: 如果是时间问题:

var show_hide = function () {
    $("#extravagents_label").fadeToggle(callblack);
}

var callblack = function () {
    $("#liquid.liquidContanier").fadeToggle()
        .delay(1500).queue(show_hide);
}

Hope this helps, still not sure what you're after 希望这会有所帮助,但仍不确定您要做什么

I have made a jsfiddle for you that modifies your code somewhat. 我为您制作了一个jsfiddle ,可以对您的代码进行一些修改。 Basically your interval is firing every 1.5 seconds whilst you're also delaying the fadeToggle on the second element. 基本上,您的间隔是每1.5秒触发一次,同时您还会延迟第二个元素上的fadeToggle。 Because you can't time how long it's going to take jQuery to fade the elements in and out, the callback handles it for you. 因为您无法确定jQuery将元素淡入和淡出需要多长时间,所以回调函数将为您处理它。

var show_hide = function () {
    $("#extravagents_label").fadeToggle(function () {
        $(this).fadeToggle();
        $("#liquid.liquidContanier").fadeToggle(function () {
            $(this).fadeToggle();
            show_hide();
        });
    });
}

setTimeout(show_hide, 1500);

Try this: 尝试这个:

jQuery : jQuery的

function show_hide() {
 $('#extravagents_label').delay(1000).fadeOut(1000).delay(1000).fadeIn(1000);
 $("#liquid .liquidContanier").delay(1000).fadeIn(1000).delay(1000).fadeOut(1000);
   //don't forgot to use space between id and it's child class
}

setInterval(show_hide,4000);
           //this timing should be total timing values of the show_hide function

guessing your css should be like: 猜你的CSS应该是这样的:

#extravagents_label { display:block; }
#liquid .liquidContanier { display:none; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM