admin管理员组

文章数量:1402781

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 ponents 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="+Icons" rel="stylesheet">

        <!--Import materialize.css-->
        <link rel="stylesheet" href=".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=".1.1.min.js"></script>
        <script src=".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=""></a>
            <a class="carousel-item" href="#two!"><img src=""></a>
            <a class="carousel-item" href="#three!"><img src=""></a>
            <a class="carousel-item" href="#four!"><img src=""></a>
        </div>
    </body>
</html>

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 ponents 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./icon?family=Material+Icons" rel="stylesheet">

        <!--Import materialize.css-->
        <link rel="stylesheet" href="https://cdnjs.cloudflare./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./jquery-2.1.1.min.js"></script>
        <script src="https://cdnjs.cloudflare./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./800/400/food/1"></a>
            <a class="carousel-item" href="#two!"><img src="http://lorempixel./800/400/food/2"></a>
            <a class="carousel-item" href="#three!"><img src="http://lorempixel./800/400/food/3"></a>
            <a class="carousel-item" href="#four!"><img src="http://lorempixel./800/400/food/4"></a>
        </div>
    </body>
</html>
Share Improve this question edited May 23, 2017 at 12:31 CommunityBot 11 silver badge asked Jul 25, 2016 at 12:26 Sanjo SimonSanjo Simon 212 gold badges2 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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

本文标签: javascriptMaterializeCSS carousel not workingStack Overflow