Reputation: 21
This is not a duplicate of this. Unlike the
I've been trying to include the MaterializeCSS carousel in a web page and I am using the latest MaterializeCSS files. All the other components works fine, except for the carousel.
I've initialized the carousel and also tried other elements and all seem to work fine.
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css">
<link type="text/css" rel="stylesheet" href="css/main.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>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"></script>
<!--Other element insitialisations-->
<script type="text/javascript" language="javascript">
$( document ).ready(function(){
$(".button-collapse").sideNav();//mobile screen menu init
$('.carousel').carousel(); //carousel init
$('.slider').slider({full_width: true});//slider init
});
</script>
<div class="carousel carousel-slider">
<a class="carousel-item" href="#one!"><img src="http://lorempixel.com/800/400/food/1"></a>
<a class="carousel-item" href="#two!"><img src="http://lorempixel.com/800/400/food/2"></a>
<a class="carousel-item" href="#three!"><img src="http://lorempixel.com/800/400/food/3"></a>
<a class="carousel-item" href="#four!"><img src="http://lorempixel.com/800/400/food/4"></a>
</div>
</body>
</html>
Upvotes: 1
Views: 14752
Reputation: 2570
You are using the wrong class to init the slider.
Use
$('.carousel-slider').slider({full_width: true});//slider init
instead of
$('.slider').slider({full_width: true});//slider init
Upvotes: 3