javascript - 了解 Bootstrap 轮播代码

标签 javascript jquery twitter-bootstrap carousel

嘿,大家好,我对 JS 和 jQuery 不太熟悉,我刚刚浏览了 carousel.js 的源代码,发现了以下代码行:

this.cycle(true)

现在循环函数看起来像这样:

  Carousel.prototype.cycle = function (e) {

    // console.log('inside cycle');
    e || (this.paused = false)

    this.interval && clearInterval(this.interval)

    this.options.interval
      && !this.paused
      && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))

    return this
  }

如果我console.log(e),我永远不会得到“true”为什么? 我所指的行可以找到 here

有人可以向我解释为什么 this.cycle() 会在该行传递值 true 吗?

谢谢。

最佳答案

循环函数内的console.log(e)应返回true。但更容易理解的代码分割是这样的:

Carousel.prototype.cycle = function (e) {

    // console.log('inside cycle');
    //e || (this.paused = false)
    if(!e){
        this.paused=false;
    }

    //this.interval && clearInterval(this.interval)
    if(this.interval){
        clearInterval(this.interval);   
    }

    /*
    this.options.interval
      && !this.paused
      && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
    */
    if(this.options.interval && !this.paused){
        this.interval = setInterval($.proxy(this.next, this), this.options.interval)
    }
    return this
  }

关于javascript - 了解 Bootstrap 轮播代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29859709/

相关文章:

javascript - 不运行 fn 时异步

javascript - 如何使用knockoutjs绑定(bind)嵌套输入

javascript - 将内容放入带有图标的列中

html - 如何将静态弹出框用于文本字段?

javascript - 我如何加载外部 html 并使其与 jquery 一起工作

javascript - Phantomjs:获取没有id的元素

JavaScript : How to capture the moment a function is called

css - 调整浏览器大小无法正确调整 div 大小 - 如此简单,我做错了什么?

javascript - NodeJS 异步函数中的返回变量

延迟加载后 jQuery 淡入图像