小编NFD*_*NFD的帖子

Bootstrap Carousel:未捕获TypeError:无法读取未定义的属性'offsetWidth'

我似乎有一个Bootstrap Carousel问题,这是发布的其他问题/修复程序所独有的。这个很奇怪。

首先,包含错误的网站:nastassiafreeman.com

二,控制台错误:

Uncaught TypeError: Cannot read property 'offsetWidth' of undefined
    at c.slide (https://www.nastassiafreeman.com/js/bootstrap.min.js:6:6890)
    at c.next (https://www.nastassiafreeman.com/js/bootstrap.min.js:6:6128)
    at e (https://www.nastassiafreeman.com/js/jquery.js:2:3957)
Run Code Online (Sandbox Code Playgroud)

第三,如何触发错误:

单击图像后,将弹出一个模态/轮播,可以进行导航。单击箭头时,将触发错误,并且您无法继续下一张图像。

奇怪的事实:

当您刷新页面并重试时,它可以工作

我的html设置为我只有1个空轮播和许多图片的地方,请注意轮播是空的:

    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">



    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
Run Code Online (Sandbox Code Playgroud)

然后,我的js文件会查找click事件,并根据点击的内容在轮播中填充图片:

  if($(this).attr('id') == 'fall_A'){
    $('.item').remove();
    $( '.carousel-inner' …
Run Code Online (Sandbox Code Playgroud)

javascript carousel twitter-bootstrap-3

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

carousel ×1

javascript ×1

twitter-bootstrap-3 ×1