My slider no works automatic mode

点点圈 提交于 2019-12-06 13:09:28

Also seems to have some scope-issues. I would put the acordeon-function inside an object literal (namespace-ish), so that you have more control over it:

Take a look at this fiddle: http://jsfiddle.net/3mfJ2/

What I've changed is basically this:

myfuncs = {
    acordeon: function(id)
        {
            $(function(){
                $(".ac_"+id+"_inf").css("width",""+final);
                $(".ac_"+id+"_inf").show(2000).fadeIn(2000);
                for (i=0;i<5;i++)
                {           
                    if (+id==i)
                    {

                    }
                    else
                    {
                        $(".ac_"+i+"_inf").hide(1000);
                    }
                }
            });
        }
}

Change that automatic for loop to

var starting_slide = 5;
function setSlide(i) {

  acordeon(i);

   if (i > 1) {
      i--;   
      setTimeout( function(){setSlide(i)}, 1000);
    }

   /* 
    //if dont want it to stop
    else {
      setTimeout( function(){setSlide(starting_slide)}, 1000);
   } */
}

​setSlide(starting_slide);​

Because your current for loop doesn't wait and executes those 5 timeouts at the same time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!