首页 > 解决方案 > JS/jQuery - setInterval 应用多次且速度太快

问题描述

实况示例:http : //www.elplastgdynia.pl/ 左侧为男人图像的框

如您所见,它一直闪烁,就像卡在其中一个动画上一样。有什么想法可能会出错吗?

JS:

function mainHeaderChange() {
    if ($mainheadercounter == 0) {
        $("#module-intro-text .container").animate({opacity: "0"}, 1500);
        setTimeout(
          function() 
          {
            $("#module-intro-text .element h1:nth-child(1)").text("Najwyższa jakość");
            $("#module-intro-text .element h1:nth-child(2)").text("oferowanych usług");
            $("#module-intro-text .element p:nth-of-type(1)").text("Potwierdzona certyfikatem jakości");
            $("#module-intro-text .element p:nth-of-type(2)").text("ISO 9001:2008");
            $("#module-intro-text button").attr("name", "linkto-quality");
          }, 1500);
        $("#module-intro-text .container").fadeTo( "slow" , 1);
        $mainheadercounter++;
    } else if ($mainheadercounter == 1) {
        $("#module-intro-text .container").animate({opacity: "0"}, 1500);
        setTimeout(
          function() 
          {
            $("#module-intro-text .element h1:nth-child(1)").text("szeroka gama");
            $("#module-intro-text .element h1:nth-child(2)").text("przetwarzanych materiałów");
            $("#module-intro-text .element p:nth-of-type(1)").text("Dobierzemy najlepsze tworzywo");
            $("#module-intro-text .element p:nth-of-type(2)").text("do Twojego projektu");
            $("#module-intro-text button").attr("name", "linkto-services");
          }, 1500);
        $("#module-intro-text .container").fadeTo( "slow" , 1);
        $mainheadercounter++;
    } else if ($mainheadercounter == 2) {
        $("#module-intro-text .container").animate({opacity: "0"}, 1500);
        setTimeout(
          function() 
          {
            $("#module-intro-text .element h1:nth-child(1)").text("OD PROJEKTU,");
            $("#module-intro-text .element h1:nth-child(2)").text("do produktu");
            $("#module-intro-text .element p:nth-of-type(1)").text("Przetwórstwo tworzyw sztucznych");
            $("#module-intro-text .element p:nth-of-type(2)").text("w technologii wtrysku");
            $("#module-intro-text button").attr("name", "linkto-offer#processtoproduct");
          }, 1500);
        $("#module-intro-text .container").fadeTo( "slow" , 1);
        $mainheadercounter = 0;
    };
};

$mainheadercounter = 0;
setTimeout(function() {setInterval(mainHeaderChange(), 8000);}, 3000);

如果实时预览不足以调查此问题,我将根据要求创建一个片段

标签: javascriptjquerysettimeoutsetinterval

解决方案


推荐阅读