[英]Understanding bootstrap carousel code
大家好,我是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' 為什么? 我所指的那行可以在這里找到。
有人可以向我解釋為什么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
}
根據代碼,如果您不傳遞任何內容或傳遞false
,也會取消暫停轉盤。 傳遞true
基本上意味着“不要自動滾動我的輪播”。 這段代碼具有神奇的作用:
this.paused = false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.