Encountering a frustrating error message: "Cannot read property 'offsetWidth' of undefined" when using Bootstrap carousel.
Let me share my code with you:
<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>
Now, let's have a look at my JavaScript code:
$("#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");
});
Trying to figure out the root of the error. Any insights?
Warm Regards, Kevin