Jquery.each使用。队列?

发布于 2024-11-26 15:38:30 字数 1394 浏览 1 评论 0原文

中有该代码

function lshow() {
        var delayt = 500;
        var showtime = 5000;
        var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
        var i=0;

        $.each(ArrayOfElements,function (i,element) {
            if($(element).is(':visible')) {
                $(element).delay(delayt).hide('slow');
            }
            if ($(element).is(':hidden')) {
                $(element).delay(showtime).show('slow');
            }

        });
    }

我在 jQuery:和 HTML:

<span class="slogan">
    <span class="slogan1">my slogan</span><!--Default visible-->
        <span class="whatwedo"><!--Default invisible-->
            projects <span class="sm">and modernization </span> of something <span class="ekon">fine</span>
        <span class="ene">fast</span>
        <span class="ekol">smooth</span>
    </span>
</span>

CSS:

.whatwedo, .sm, .ene, .ekol {
   display: none;
}

,我想将其设置为如下所示:

  1. 我的口号

fadeOut

  1. 项目的一些很好的

"fine" fadeOut "fast" fadeIn

  1. 快速的项目

相同的事情

  1. 平滑的
  2. 项目和现代化的项目

但 5 秒后。它显示 “项目和现代化的东西精细快速顺利” 我无法让它工作

I have that code in jQuery:

function lshow() {
        var delayt = 500;
        var showtime = 5000;
        var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
        var i=0;

        $.each(ArrayOfElements,function (i,element) {
            if($(element).is(':visible')) {
                $(element).delay(delayt).hide('slow');
            }
            if ($(element).is(':hidden')) {
                $(element).delay(showtime).show('slow');
            }

        });
    }

and HTML:

<span class="slogan">
    <span class="slogan1">my slogan</span><!--Default visible-->
        <span class="whatwedo"><!--Default invisible-->
            projects <span class="sm">and modernization </span> of something <span class="ekon">fine</span>
        <span class="ene">fast</span>
        <span class="ekol">smooth</span>
    </span>
</span>

CSS:

.whatwedo, .sm, .ene, .ekol {
   display: none;
}

And I want to set it appear like that:

  1. My slogan

fadeOut

  1. projects of something fine

"fine" fadeOut "fast" fadeIn

  1. projects of something fast

same thing

  1. projects of something smoth
  2. projects and modernization of something

But after 5 sec. it shows
"projects and modernization of something fine fast smoth"
and i cant get it working

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

始于初秋 2024-12-03 15:38:30

试试这个 http://jsfiddle.net/Kt38f/

 $(document).ready(function() {
    var delayt = 500;
    var showtime = 5000;
    var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
    var i=0;

            $('.slogan1').fadeOut(delayt, function(){        
                $(".whatwedo").fadeIn(showtime , function(){
                    $('.ekon').fadeOut(showtime , function(){ 
                        $('.ene').fadeIn(showtime, function(){
                            $('.ene').fadeOut(showtime, function(){ 
                                $('.ekol').fadeIn(showtime, function(){ 
                                   $('.sm').fadeIn(showtime);
                                });
                            });   
                        });
                    });
                });
            });         
});

Try this http://jsfiddle.net/Kt38f/

 $(document).ready(function() {
    var delayt = 500;
    var showtime = 5000;
    var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
    var i=0;

            $('.slogan1').fadeOut(delayt, function(){        
                $(".whatwedo").fadeIn(showtime , function(){
                    $('.ekon').fadeOut(showtime , function(){ 
                        $('.ene').fadeIn(showtime, function(){
                            $('.ene').fadeOut(showtime, function(){ 
                                $('.ekol').fadeIn(showtime, function(){ 
                                   $('.sm').fadeIn(showtime);
                                });
                            });   
                        });
                    });
                });
            });         
});
累赘 2024-12-03 15:38:30

这是另一种方法:

不是将元素放入数组中,而是将应执行的函数放入数组中,并使用setTimeout对其进行处理:

function lshow() {
    var intv = 5000;
    var funcs = [
        function() {
            $('.slogan1').hide('slow');
            $('.whatwedo').show('slow');
        },
        function() {
            $('.ekon').hide('slow');
            $('.ene').show('slow');
        },
        function() {
            $('.ene').hide('slow');
            $('.ekol').show('slow');
        },
        function() {
            $('.sm').show('slow');
        }
    ];
    var i = 0;

    setTimeout(function() {
        var func = funcs[i];
        if(func) {
            i++;
            func();
            setTimeout(arguments.callee, intv);
        }
    }, intv);
}

演示

Here is another way:

Instead of putting the elements in an array, you put the functions that should be executed in an array and process it using setTimeout:

function lshow() {
    var intv = 5000;
    var funcs = [
        function() {
            $('.slogan1').hide('slow');
            $('.whatwedo').show('slow');
        },
        function() {
            $('.ekon').hide('slow');
            $('.ene').show('slow');
        },
        function() {
            $('.ene').hide('slow');
            $('.ekol').show('slow');
        },
        function() {
            $('.sm').show('slow');
        }
    ];
    var i = 0;

    setTimeout(function() {
        var func = funcs[i];
        if(func) {
            i++;
            func();
            setTimeout(arguments.callee, intv);
        }
    }, intv);
}

DEMO

梦幻之岛 2024-12-03 15:38:30

我采取了一些不同的方法。小提琴@ http://jsfiddle.net/SinS3i/xwc9a/1/

var currentStep = false;
var t = false;
ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
var delayt = 500;
var showtime = 5000;
lshow = function(elements) {
    var lastStep = currentStep;
    currentStep = elements.shift();
    var hideIt = lastStep ? $(lastStep).has(currentStep).length === 0 : false;
    if(hideIt) {
        $(lastStep).fadeOut(showtime, function() {
            $(currentStep).fadeIn(showtime, function() {
                t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;                    
            });
        });
    } else {
        $(currentStep).fadeIn(showtime, function() {
            t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;
        });
    }
};
$(document).ready(function(){
    t = setTimeout("lshow(ArrayOfElements)", delayt);
});

I took a little bit of a different approach to it. Fiddle @ http://jsfiddle.net/SinS3i/xwc9a/1/

var currentStep = false;
var t = false;
ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
var delayt = 500;
var showtime = 5000;
lshow = function(elements) {
    var lastStep = currentStep;
    currentStep = elements.shift();
    var hideIt = lastStep ? $(lastStep).has(currentStep).length === 0 : false;
    if(hideIt) {
        $(lastStep).fadeOut(showtime, function() {
            $(currentStep).fadeIn(showtime, function() {
                t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;                    
            });
        });
    } else {
        $(currentStep).fadeIn(showtime, function() {
            t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;
        });
    }
};
$(document).ready(function(){
    t = setTimeout("lshow(ArrayOfElements)", delayt);
});
生生漫 2024-12-03 15:38:30

稍作编辑(http://jsfiddle.net/dVJvc/)

编辑:抱歉我没有看到你的回复。 (代码与上一个 ShankarSangoli 相同)

Little bit edited (http://jsfiddle.net/dVJvc/):

EDIT: Sorry i didnt see yours responses. (THE CODE IS THAT SAME AS last ShankarSangoli)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文