Using Materialize CSS v1.0.0 (without using JQuery), inserting a Carousel component into a Collapsible does not get the behavior expected (you can not see the image strip and the slide effect is damaged).
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link type="text/css" rel="stylesheet" href="css/materialdesignicons.css"/>
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div class="carousel">
<a class="carousel-item" href=""><img src="images/varelajp2.jpg"></a>
<a class="carousel-item" href=""><img src="images/varelajp3.jpg"></a>
<a class="carousel-item" href=""><img src="images/varelajp4.jpg"></a>
</div>
<ul class="collapsible">
<li>
<div class="collapsible-header"><i class="material-icons">whatshot</i>Carousel on it</div>
<div class="collapsible-body">
<div class="carousel" id="carouselSports">
<a class="carousel-item" href=""><img src="images/varelajp2.jpg"></a>
<a class="carousel-item" href=""><img src="images/varelajp3.jpg"></a>
<a class="carousel-item" href=""><img src="images/varelajp4.jpg"></a>
</div>
</div>
</li>
</ul>
<!--JavaScript at end of body for optimized loading-->
<script type="text/javascript" src="js/materialize.min.js"></script> <!--No se inserta JQuery.js-->
<script type="text/javascript">M.AutoInit();</script>
</body>
</html>
Some solutions suggest initializing the Carousel in the OnOpen callback (currently OnOpenStart) of the collapsible plugin. Something like:
$('.collapsible').collapsible({
onOpen: function() {
$('.carousel').carousel();
}
})
The above solution is for Materialize CSS versions using JQuery.
It occurs to me to imitate it by initializing as indicated by the new version (with pure Javascript):
document.addEventListener('DOMContentLoaded', function() {
var collapsibles = document.querySelectorAll('.collapsible');
var instanceCollapsibles = M.Collapsible.init(collapsibles, {
onOpenStart: function() {
var carousels = M.Carousel.getInstance(document.getElementById('carouselSports'));
var instanceCarousels = M.Carousel.init(carousels, {
indicators: true
});
}
});
});
The OpenStart event of the Collapsible is well captured (tested with console.log ), but the Carousel still does not behave correctly.
Any clues?