[英]Getting Cannot read property 'offsetWidth' of undefined with bootstrap carousel script
[英]Getting Cannot read property 'offsetWidth' of undefined with Bootstrap carousel error message
我收到以下錯誤消息:Getting Cannot read property 'offsetWidth' of undefined with Bootstrap carousel error message with my Bootstrap carousel。
這是我的代碼:
<div id="myCarousel" class="carousel slide" >
<ul class="carousel-indicators">
<?php foreach ($repairPics as $ind => $pics) { ?>
<li data-target="#myCarousel" data-slide-to="<?php echo $ind;?>" <?php echo (($ind == 0) ? 'class="active"' : '');?>"></li>
<?php } ?>
</ul>
<div class="carousel-inner" role="listbox" style="margin-left: 10%;height: 100%;">
<?php foreach ($repairPics as $ind => $pics) { ?>
<div class="carousel-item <?php echo (($ind == 0) ? 'active' : '');?>">
<img style="height: 100%;" class="d-inline-block w-100" src="https://earthsky.org/upl/2017/06/Interplanetary-Transport-System-SpaceX-Elon-Musk-300x158.jpg" alt="Starship">
</div>
<?php } ?>
</div>
<a class="carousel-nav-controls carousel-control-prev" href="#myCarousel" data-slide="prev">
<span class="fa fa-chevron-left"></span><span class="sr-only">Previous</span>
</a>
<a class="carousel-nav-controls carousel-control-next" href="#myCarousel" data-slide="next" style="right: 0%;">
<span class="fa fa-chevron-right"></span><span class="sr-only">Next</span>
</a>
</div>
</div>
這是我的js代碼:
$("#myCarousel").carousel();
$(".carousel-item").click(function(){
$("#myCarousel").carousel(0);
});
$("a.carousel-nav-controls.carousel-control-prev").click(function(){
$("#myCarousel").carousel("prev");
});
$("a.carousel-nav-controls.carousel-control-next").click(function(){
$("#myCarousel").carousel("next");
});
什么可能導致錯誤?
泰,凱文
解析度:
問題不在 Javascript 中,也不在活動設置中。 它與 carousel-item 類有關。 我將它從 carousel-item 更改為 item。 它現在正在工作。 看起來我可能需要升級 Bootstrap。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.