简体   繁体   English

实现-使用轮播功能

[英]Materialize - Using Carousel functionalities

I just want to use the carousel from Materialize with the following features : I want to use it on full width, with navigations buttons and the specials fixed-item option. 我只想使用Materialize的轮播,并具有以下功能:我想在全宽度上使用它,并带有导航按钮和特殊的固定项目选项。

But the navigations buttons doesn't work. 但是导航按钮不起作用。 Here is the code I used to test that! 这是我用来测试的代码!

 $(document).ready(function(){ $('.carousel').carousel(); }); $('.carousel.carousel-slider').carousel({fullWidth: true}); $('.slide-prev').carousel('prev'); $('.slide-next').carousel('next'); 
 <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" rel="stylesheet"/> <div class="carousel carousel-slider center" data-indicators="true"> <div class="carousel-fixed-item center"> <a class="btn waves-effect white grey-text darken-text-2 slide-prev">Prev</a> <a class="btn waves-effect white grey-text darken-text-2">Share</a> <a class="btn waves-effect white grey-text darken-text-2 slide-next">Next</a> </div> <div class="carousel-item red white-text" href="#one!"> <h2>First Panel</h2> <p class="white-text">This is your first panel</p> </div> <div class="carousel-item amber white-text" href="#two!"> <h2>Second Panel</h2> <p class="white-text">This is your second panel</p> </div> <div class="carousel-item green white-text" href="#three!"> <h2>Third Panel</h2> <p class="white-text">This is your third panel</p> </div> <div class="carousel-item blue white-text" href="#four!"> <h2>Fourth Panel</h2> <p class="white-text">This is your fourth panel</p> </div> </div> 

What's wrong here? 怎么了 Thank you for your help! 谢谢您的帮助! ~W~ 〜W〜

You'll need have click handlers for the buttons which stop the propagation and perform the needed operation on the carousel element, instead of performing it on the button element. 您将需要按钮的单击处理程序,以停止传播并在轮播元素上执行所需的操作,而不是在按钮元素上执行该操作。

Here is a snippet: 这是一个片段:

    $(document).ready(function () {
    $('.carousel').carousel();
    $('.carousel.carousel-slider').carousel({ fullWidth: true });
    $('.slide-prev').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        $('.carousel').carousel('prev')
    });
    $('.slide-next').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        $('.carousel').carousel('next')
    });
});

Here is a Codepen to see it work: https://codepen.io/zubair1024/pen/mBaEdX 这是一个Codepen可以看到它的工作原理: https ://codepen.io/zubair1024/pen/mBaEdX

For navigation (programmatically) use the following: 对于导航(以编程方式),请使用以下命令:

 //this is for navigation using a new tab
        $('.share-btn').click(function (e) {
            var win = window.open('http://google.com', '_blank');
            win.focus();
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM