这个文本转换器工作正常,但我需要不断循环

时间:2013-12-19 11:12:39

标签: javascript jquery

var arrNames = [
            '<span class="highlight">For All Joinery & Building Requirements.</span>',
            '<span class="highlight">No Job Too Small, No VAT Charges, Free Estimates!</span>',
            '<span class="highlight">Hardwood, Softwood & UPVC Windows, Doors, Porches & Conservatories.</span>',
            '<span class="highlight">Extensions, UPVC Soffits & Facias, Roof & Renovation Work & Loft Conversions.</span>',
            '<span class="highlight">Kitchens & Bathrooms designed & Installed with a full tiling service available.</span>',
            '<span class="highlight">For your free quote, call us today!/span>',
        ];

            $.each(arrNames, function(i, val) {
                setTimeout(function() {
                    $('.quotes').fadeOut("slow", function() {
                        $(this).html(val).fadeIn("slow");
                    });
                }, i * 8000);

            });

我将如何重复此功能以使其保持循环,它完美地播放一次。

1 个答案:

答案 0 :(得分:0)

您应该使用setInterval以及setTimeout

<强> Working Fiddle

$.each(arrNames, function(i, val) {
            setTimeout(function() {
                $('.quotes').fadeOut("slow", function() {
                    $(this).html(val).fadeIn("slow");
                });
            }, i * 8000);
        });
setInterval(function(){   
$.each(arrNames, function(i, val) {
            setTimeout(function() {
                $('.quotes').fadeOut("slow", function() {
                    $(this).html(val).fadeIn("slow");
                });
            }, i * 8000);
        });
},48000);