Javascript 如何';修理';我的猫头鹰在摧毁它之后
我有一个产品页面,每个产品都是模态,每个模态都是owl滑块 当我第一次看到一个产品时,它显示得很好,但是当我关闭该产品并打开另一个产品时,owl滑块就坏了 我试过(或者我觉得我试过)我在互联网上找到的每一个解决方案,但我仍然无法找到它 这是我的jQuery:Javascript 如何';修理';我的猫头鹰在摧毁它之后,javascript,jquery,twitter-bootstrap,owl-carousel,Javascript,Jquery,Twitter Bootstrap,Owl Carousel,我有一个产品页面,每个产品都是模态,每个模态都是owl滑块 当我第一次看到一个产品时,它显示得很好,但是当我关闭该产品并打开另一个产品时,owl滑块就坏了 我试过(或者我觉得我试过)我在互联网上找到的每一个解决方案,但我仍然无法找到它 这是我的jQuery: var owlCarousel = $('.owl-carousel'); $('.modal').on('shown.bs.modal', function (event) { owlCarousel.owlCarousel({
var owlCarousel = $('.owl-carousel');
$('.modal').on('shown.bs.modal', function (event) {
owlCarousel.owlCarousel({
loop: true,
items: 1,
margin: 100
});
});
$('.modal').on('hidden.bs.modal', function (event) {
$('.owl-carousel').trigger('destroy.owl.carousel');
});
我希望我能很好地解释我的问题
注意:当我打开第二个产品时,每等待一秒钟就会出现此错误
尝试检查
可见的owlCarousel元素,并调用owlCarousel
和destroy
事件
var owlCarousel;
$('.modal').on('shown.bs.modal', function (event) {
owlCarousel = $('.owl-carousel:visible');
owlCarousel.owlCarousel({
loop: true,
items: 1,
margin: 100
});
});
$('.modal').on('hidden.bs.modal', function (event) {
owlCarousel.trigger('destroy.owl.carousel');
});
在owl.carousel.js的第620行中,更改以下内容:
Owl.prototype.onThrottledResize = function() {
window.clearTimeout(this.resizeTimer);
this.resizeTimer = window.setTimeout(this.e._onResize, this.settings.responsiveRefreshRate);
};
为此:
Owl.prototype.onThrottledResize = function() {
if(this.e !=null) {
window.clearTimeout(this.resizeTimer);
this.resizeTimer = window.setTimeout(this.e._onResize, this.settings.responsiveRefreshRate);
}
};
为我工作:)谢谢你的评论,但是当我使用这个时,我的整个滑块都断了。你能提供一把小提琴吗?
Owl.prototype.onThrottledResize = function() {
if(this.e !=null) {
window.clearTimeout(this.resizeTimer);
this.resizeTimer = window.setTimeout(this.e._onResize, this.settings.responsiveRefreshRate);
}
};