How to tell Bootstrap Carousel to skip an element or class?

守給你的承諾、 提交于 2019-12-13 01:29:43

问题


I'm using Bootstrap Carousel for Tumblr and it works great. However, on the theme customization page Tumblr adds JavaScript to the HTML left, right and center. That's causing the carousel to break, because the next element is unexpected.

To simply put it in code it looks like this

<div class="carousel-inner">
  <div class="active item"></div>
  <script class="custom-js-code">/* bunch of stuff go here */</script>
  <div class="item"></div>
  <script class="custom-js-code">/* bunch of stuff go here */</script>
  <div class="item"></div>
  <script class="custom-js-code">/* bunch of stuff go here */</script>
</div>

Live preview

Removing the JS is out of the question, so I need a way to tell the carousel to skip those elements using the <script> tag or the custom-js-code class.

Any ideas?


回答1:


If possible upgrade to Bootstrap 3.2.0 as that version only iterates over children with class .item.

  • See http://codepen.io/ckuijjer/pen/RNaJbx for your code using Bootstrap 3.2.0
  • See https://github.com/twbs/bootstrap/blob/master/js/carousel.js for the carousel source code
  • See https://github.com/twbs/bootstrap/commit/4a2d337bf5f329eac1ca16208414ec1ebfe0546e for the changeset where this behavior changed

If you can't move to version 3.2.0 perhaps see if it's possible to make this change to the source code yourself.



来源:https://stackoverflow.com/questions/27468089/how-to-tell-bootstrap-carousel-to-skip-an-element-or-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!