javascript - Slick.js use links as controls - Stack Overflow

So I am using the slick.js plugin for my slider (never really used it before but thought I would give i

So I am using the slick.js plugin for my slider (never really used it before but thought I would give it a try!)

So anyway, I am wanting to use a custom set of

  • tags as my controls, these will never change and the image associated to the links in the slider will never change.

                <script type="text/javascript">
                    $(function () {
                        var $panel = $('<div class="panel">13</div>');
                        var slickOpts = {
                            slidesToShow: 1,
                            slidesToScroll: 1,
                            dots: false,
                            fade: true,
                            autoplay: true,
                            prevArrow: '.btn-prev',
                            nextArrow: '.btn-next'
                        };
                        // Init the slick
                        $('#dashboard').slick(slickOpts);
                        var slickEnabled = false;
    
                    });
                </script>
    
    <div id="dashboard">
    <div class="panel">1</div>
    <div class="panel">2</div>
    <div class="panel">3</div>
    <div class="panel">5</div>
    </div>
    

    So I am wanting to sue this list to control the 5 slides:

    <div class="mobileSubNav">
    <ul class="mobile_nav_list">
    <a href="#"><li><span class="mobile-icon"></span>landscaping</li></a>
    <a href="#"><li><span class="mobile-icon"></span> grounds maintinence</li></a>
    <a href="#"><li><span class="mobile-icon"></span> tree surgery</li></a>
    <a href="#"><li><span class="mobile-icon"></span> fencing</li></a>
    <a href="#"><li><span class="mobile-icon"></span> winter maintinence</li></a>
    </ul>
    </div>
    

    So I am using the slick.js plugin for my slider (never really used it before but thought I would give it a try!)

    So anyway, I am wanting to use a custom set of

  • tags as my controls, these will never change and the image associated to the links in the slider will never change.

                <script type="text/javascript">
                    $(function () {
                        var $panel = $('<div class="panel">13</div>');
                        var slickOpts = {
                            slidesToShow: 1,
                            slidesToScroll: 1,
                            dots: false,
                            fade: true,
                            autoplay: true,
                            prevArrow: '.btn-prev',
                            nextArrow: '.btn-next'
                        };
                        // Init the slick
                        $('#dashboard').slick(slickOpts);
                        var slickEnabled = false;
    
                    });
                </script>
    
    <div id="dashboard">
    <div class="panel">1</div>
    <div class="panel">2</div>
    <div class="panel">3</div>
    <div class="panel">5</div>
    </div>
    

    So I am wanting to sue this list to control the 5 slides:

    <div class="mobileSubNav">
    <ul class="mobile_nav_list">
    <a href="#"><li><span class="mobile-icon"></span>landscaping</li></a>
    <a href="#"><li><span class="mobile-icon"></span> grounds maintinence</li></a>
    <a href="#"><li><span class="mobile-icon"></span> tree surgery</li></a>
    <a href="#"><li><span class="mobile-icon"></span> fencing</li></a>
    <a href="#"><li><span class="mobile-icon"></span> winter maintinence</li></a>
    </ul>
    </div>
    
    Share Improve this question edited Nov 10, 2016 at 14:11 Ahmad Alfy 13.4k6 gold badges68 silver badges102 bronze badges asked Feb 18, 2015 at 17:04 coder123coder123 1831 gold badge4 silver badges15 bronze badges
    Add a ment  | 

    1 Answer 1

    Reset to default 8

    You'll need to use the slickGoTo method.

    Example: http://jsfiddle/j7tua7rL/

    HTML

    <section class="slider">
        <div>slide1</div>
        <div>slide2</div>
        <div>slide3</div>
        <div>slide4</div>
        <div>slide5</div>
        <div>slide6</div>
    </section>
    
    <ul class="links">
        <li><a href="#">Slide 1</a></li>
        <li><a href="#">Slide 2</a></li>
        <li><a href="#">Slide 3</a></li>
        <li><a href="#">Slide 4</a></li>
        <li><a href="#">Slide 5</a></li>
        <li><a href="#">Slide 6</a></li>
    </ul>
    

    JS

    var $slideshow = $(".slider").slick();
    
    $('.links').on('click', 'a', function( e ) {
    
        var slideIndex = $(this).closest('li').index();
    
        $slideshow.slick( 'slickGoTo', parseInt( slideIndex ) );
    
        e.preventDefault();
    });
    

    发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744995737a4605177.html

  • 相关推荐

    • javascript - Slick.js use links as controls - Stack Overflow

      So I am using the slick.js plugin for my slider (never really used it before but thought I would give i

      18小时前
      30

    发表回复

    评论列表(0条)

    • 暂无评论

    联系我们

    400-800-8888

    在线咨询: QQ交谈

    邮件:admin@example.com

    工作时间:周一至周五,9:30-18:30,节假日休息

    关注微信