简体   繁体   English

销毁/删除引导轮播

[英]Destroy/remove bootstrap carousel

First, I created a virtual carousel (carousel elements) and then initialize it 首先,我创建了一个虚拟轮播(轮播元素),然后对其进行了初始化

$('#first-carousel').carousel();

Now, I run unto scenario where if window width is less than 480 then remove that carousel (#first-carousel'). 现在,我遇到以下情况:如果窗口宽度小于480,则删除该转盘(#first-carousel')。

How to remove bootstrap carousel? 如何删除引导轮播? Tried to check its doc but seems there's no something like destroy or remove function or any related. 试图检查其文档,但似乎没有破坏或删除功能或任何相关内容。 Tried 试着

$('#first-carousel').remove();
$('#first-carousel').unbind();

but seems not working, instead it gives me this error 但似乎不起作用,相反,它给了我这个错误

bootstrap.min.js:6 Uncaught TypeError: Cannot read property 'offsetWidth' of undefined at c.slide (bootstrap.min.js:6) at c.next (bootstrap.min.js:6) at e (jquery.min.js:2) bootstrap.min.js:6未捕获的TypeError:无法在e(jquery.min)的c.next(bootstrap.min.js:6)的c.slide(bootstrap.min.js:6)读取未定义的属性'offsetWidth'的.js:2)

any help, ideas? 任何帮助,想法?

Apparently there are no way to do it in Boostrap 3. What you can do is only initialize the carousel if the viewport is greater or equal to 480px. 显然,在Boostrap 3中无法执行此操作。仅当视口大于或等于480px时,才可以初始化轮播。

if(window.innerWidth >= 480){
  $('#first-carousel').carousel();
}

The code $('#first-carousel').remove(); 代码$('#first-carousel').remove(); does remove the element with that given id. 确实删除具有给定id的元素。 You might be having an issue with the condition for window width possibly, are you sure you aren't having a different issue here? 您可能对窗口宽度的条件有疑问,您确定这里没有其他问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM