javascript - Slick slider appendArrows to multiple containers, arrows not working except last one - Stack Overflow

I am trying to append slick arrows to multiple containers. Basically, I need every slide to have its ow

I am trying to append slick arrows to multiple containers. Basically, I need every slide to have its own navigation. Every slide has

<div class="pixoff-slider-navigation-anchor"></div>

somewhere inside it. My JS code is

$('.pixoff-slider-container').slick({
    arrows: true
    ,appendArrows: $('.pixoff-slider-navigation-anchor')
});

This works, and it appends arrows to all the containers, but only latest set of arrows actually works. Other ones are just there and do nothing when we click on them.

I am trying to append slick arrows to multiple containers. Basically, I need every slide to have its own navigation. Every slide has

<div class="pixoff-slider-navigation-anchor"></div>

somewhere inside it. My JS code is

$('.pixoff-slider-container').slick({
    arrows: true
    ,appendArrows: $('.pixoff-slider-navigation-anchor')
});

This works, and it appends arrows to all the containers, but only latest set of arrows actually works. Other ones are just there and do nothing when we click on them.

Share Improve this question edited Aug 29, 2018 at 9:13 Bahman Parsa Manesh 2,3703 gold badges18 silver badges36 bronze badges asked Aug 29, 2018 at 8:39 Milos911Milos911 4334 gold badges9 silver badges21 bronze badges 2
  • What is the click event for anchors? – Milind Anantwar Commented Aug 29, 2018 at 8:44
  • I get what you are asking, but I am not sure how to check that? @MilindAnantwar – Milos911 Commented Aug 30, 2018 at 7:01
Add a ment  | 

2 Answers 2

Reset to default 3

If you are using several slider in one page, you should add additional script for this.

$(window).on("load resize orientationchange", function () {
    $(".slider").each(function () {
        var slider = $(this);
    
        slider.slick({
            centerMode: false,
            centerPadding: '60px',
            arrows: true,
            dots: true,
            slidesToShow: 3,
            autoplay: true,
            prevArrow: slider.parent().find('.btnPrev'),
            nextArrow: slider.parent().find('.slider__btnNext'),
            
        });
    });
});

and HTML looks like this

<div class="sliderParent">
    <button class="btnPrev"></button>
    <button class="btnNext"></button>
    <div class="slider">
        <div class="item">a</div>
        <div class="item">b</div>
        <div class="item">c</div>
        <div class="item">d</div>
    </div>
</div>

Instead of appending the arrow to the dom, write the html you want in each slide and then set the prev and next arrows in your slick options.

$('.pixoff-slider-container').slick({
        arrows: true,
        dots: false,
        prevArrow: $('.prev-arrow'),
        nextArrow: $('.next-arrow')
    });
<div class="pixoff-slider-navigation-anchor">
  <a class="prev-arrow">Prev</a>
  <a class="next-arrow">Next</a>
</div>

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信