admin管理员组文章数量:1393380
I have several instances of the Slick Carousel gallery set up and working properly. However, I cannot successfully call the Methods as described in the documentation. (/)
Whenever I try to target an existing instance of the carousel, I get the following error: "Uncaught TypeError: Cannot read property 'changeSlide' of undefined." I'm trying to automatically goto the next slide after the gallery is initiated.
I've put together this jsfiddle to replicate the issue: /
var gallery = $('.slick-container');
gallery.slick({
speed:100,
dots:true,
onInit: function(){
gallery.slickNext();
}
});
Error:
Uncaught TypeError: Cannot read property 'changeSlide' of undefined
Targeting this, $(this), $('.slick-container'), and gallery all produce the same exception. Any help is greatly appreciated, thank you!!
EDIT
Thanks to Sunand for the fix! For those dealing with the same issue, simply move your method out of the onInit callback. Apparently the slick instance is not fully initialized when onInit is called. Here's the correct code:
var gallery = $('.slick-container');
gallery.slick({
speed:100,
dots:true,
});
gallery.slickNext();
I have several instances of the Slick Carousel gallery set up and working properly. However, I cannot successfully call the Methods as described in the documentation. (http://kenwheeler.github.io/slick/)
Whenever I try to target an existing instance of the carousel, I get the following error: "Uncaught TypeError: Cannot read property 'changeSlide' of undefined." I'm trying to automatically goto the next slide after the gallery is initiated.
I've put together this jsfiddle to replicate the issue: http://jsfiddle/d32x7nqp/
var gallery = $('.slick-container');
gallery.slick({
speed:100,
dots:true,
onInit: function(){
gallery.slickNext();
}
});
Error:
Uncaught TypeError: Cannot read property 'changeSlide' of undefined
Targeting this, $(this), $('.slick-container'), and gallery all produce the same exception. Any help is greatly appreciated, thank you!!
EDIT
Thanks to Sunand for the fix! For those dealing with the same issue, simply move your method out of the onInit callback. Apparently the slick instance is not fully initialized when onInit is called. Here's the correct code:
var gallery = $('.slick-container');
gallery.slick({
speed:100,
dots:true,
});
gallery.slickNext();
Share
Improve this question
edited Sep 23, 2014 at 22:17
ixninja
asked Sep 22, 2014 at 19:53
ixninjaixninja
7466 silver badges17 bronze badges
3
- can you tell how are you calling the methods? – Sunand Commented Sep 22, 2014 at 20:41
- Sunand, please see the jsfiddle that I included in my post. – ixninja Commented Sep 23, 2014 at 14:18
- 1 the error is because that ponent is not pletely initialised when onInit is called. If just want to call next after initialisation call it after you call the slick plugin. – Sunand Commented Sep 23, 2014 at 18:31
1 Answer
Reset to default 6I'm noticing after upgrading my slick.js a lot of the methods like slickPrev() etc are gone. Looks like the way to call them now seems to be
$('selector').slick('slickPrev');
本文标签: javascriptSlick Carousel unable to call MethodsStack Overflow
版权声明:本文标题:javascript - Slick Carousel unable to call Methods - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744647463a2617483.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论