Jquery setInterval() not working

前端 未结 5 2073
野性不改
野性不改 2020-12-20 16:30

I\'m trying to create a kind of slideshow.

The problem:

function slides(x) {
      $(\"#irack\").stop().animate({\"left\": x}, 20);
 };
setInterval         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 17:11

    Oh, I've found the problem :D

    $("#irack").stop().animate({"left": x}, 20);
    

    The problem is that "x" is a constant, and it changes the "left" to x and keeps it that way.

    I should do this way:

    x=$("#irack").offset().left+x;
    $("#irack").stop().animate({"left": x}, 20);
    

    And thanks a lot for pointing that "wrapping" stuff :D.

提交回复
热议问题