【问题标题】:jQuery How to properly set an interval?jQuery 如何正确设置间隔?
【发布时间】:2013-04-16 17:00:53
【问题描述】:

目前我有这个,但它一直返回“swapBKgnd is no defined”:

    var interval = self.setInterval("swapBKgnd()", 9000);

function swapBKgnd() {

    (direction === 'next') ? ++current : --current;

    if (current === 0) {
        current = imgsLenth;
        direction = 'next';
    } else if (current - 1 === imgsLenth) {
        current = 1;
        loc = 0;
    }


    transition(sliderUL, loc, direction);
};

谢谢。

【问题讨论】:

  • 尝试在function 之后声明var interval :)
  • var 间隔 = setInterval(swapBKgnd, 9000);
  • 删除swapBKgnd()的引号。
  • @karthikr 和 '()' 否则它会立即调用函数
  • @the-val 嗯,没有返回任何错误...但似乎仍然无法正常工作。

标签: jquery slider setinterval intervals


【解决方案1】:

swapBKgnd() 中删除引号。

使用可以做:

var interval = self.setInterval(swapBKgnd, 9000);

您尚未声明 directioncurrentloc - 这些会引发错误

【讨论】:

  • "var 间隔 = self.setInterval(swapBKgnd(), 9000);"这是错误的,“var interval = self.setInterval("swapBKgnd", 9000);"也错了
  • 我还没有发布整个脚本。前面已经定义了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-09
  • 2021-11-16
  • 2022-12-21
  • 1970-01-01
  • 1970-01-01
  • 2013-01-25
相关资源
最近更新 更多