Javascript 理解carasour.js中的返回
嘿,伙计们,我是Jquery/JS新手,一般来说,我只是浏览了的代码,遇到了以下几行代码:Javascript 理解carasour.js中的返回,javascript,jquery,Javascript,Jquery,嘿,伙计们,我是Jquery/JS新手,一般来说,我只是浏览了的代码,遇到了以下几行代码: Carousel.prototype.slide = function (type, next) { var $active = this.$element.find('.item.active') var $next = next || this.getItemForDirection(type, $active) var isCycling = this.int
Carousel.prototype.slide = function (type, next) {
var $active = this.$element.find('.item.active')
var $next = next || this.getItemForDirection(type, $active)
var isCycling = this.interval
var direction = type == 'next' ? 'left' : 'right'
var that = this
if ($next.hasClass('active')) return (this.sliding = false)
// ALOT MORE CODE
isCycling && this.cycle()
return this
}
我的困难在于理解返回这个最后,为什么是这行代码
如果您使用carasour.js插件,slide()
函数将在函数next()
和prev()
中调用
现在插件中的许多函数返回结果,例如getItemForDirection()
函数
Carousel.prototype.getItemForDirection = function (direction, active) {
// SOME CODE AND CALCULATIONS
return this.$items.eq(itemIndex)
}
我知道需要返回一个结果,但在slide()函数中,为什么要返回这个结果
几天前,我读了一篇关于js链接的文章,但不知何故,我不理解幻灯片函数中返回这个的实际用法
Carousel.prototype.getItemForDirection = function (direction, active) {
// SOME CODE AND CALCULATIONS
return this.$items.eq(itemIndex)
}
有人能解释一下吗?一个实际的例子会很有帮助
谢谢
Alex-z.用于呼叫链接。您可以通过链接执行以下操作:
carouselInstance.slide().next().cycle().to(5);
另一方面,getItemForDirection()
方法应该返回一些项,这样它就不能在这种情况下使用。看一看,我理解这一部分,但我不理解carasoul上下文中的链接。jsI修改了我的示例,向您展示了旋转木马中更高级的链接。例如,如果您想在转到特定幻灯片后将旋转木马设置为“暂停”:carouselInstance.slide().pause()代码>