4

I'm using slick.js to power a slider. I'd like to remove the "previous" arrow when the first slide is active and the "next" arrow when the last slide is active. I may need to remove both arrows when the final slide is active. Is there a slick event function or a jquery function that can do this?

2
  • why you want to remove both arrow on final slide? Also you mentioned you want to remove next arrow on last slide. What do you mean by last and final slide? They are one and the same right? Commented Feb 13, 2016 at 23:45
  • Yes, they are the same. So if I'm on the last slide, I don't want the next arrow to appear - because there isn't a next slide, and I don't want to start over.
    – heytricia
    Commented Feb 16, 2016 at 22:46

3 Answers 3

8

To disable previous arrow on first slide and next arrow on last slide you could define infinite : false, on slick initialization like below.

 $("#slider").slick({
        infinite : false
  });

if you have additional settings just include that in initialization. slider is id of container.

This is to disable arrows on Slider. To remove arrows you could just hide it when first/last slide is active. Go through documentation on how to get active slide on slider and with jquery hide you could hide arrow by class name of arrow button. You could get class/id of arrow button by inspecting element. Right click on arrow and inspect it.

To get current slide: $('#slider').slick('slickCurrentSlide');

To hide or show next arrow: $('.slick-next').show(); or $('.slick-next').hide();

Similarly for prev arrow: $('.slick-prev').show(); or $('.slick-prev').hide();

Heres Fiddle: https://jsfiddle.net/pjfw1wqz/

1
  • Thank you! I had added the setting "infinite:false", but the arrows were still visible and I thought I had misunderstood the setting. It was Friday and the end of a very long week - I was brain dead! Now that I look at it more closely, I see that even though the button is set to display, it also is disabled. I can target the disabled class to hide the buttons. The user will still have access to the nav dots, and can start over if necessary. Thank you also for helping me to understand how to work with afterChange. This is what I thought I needed, and I can do more if necessary.
    – heytricia
    Commented Feb 16, 2016 at 23:16
0
        // slick init
        startSlick();
        var tickerDiv = $("#animatedHeading");
        function startSlick(slick) {  
            tickerDiv.slick({
                arrows: true,
                infinite: false,
                adaptiveHeight: true
              });
                var current_article = tickerDiv.slick('slickCurrentSlide');
                var total_articles = tickerDiv.slideCount;
                tickerDiv.on('init reInit afterChange', function(event, slick, currentSlide, nextSlide){
                    current_article = tickerDiv.slick('slickCurrentSlide');
                    total_articles = slick.slideCount;
                    slickArrow();
                });
                slickArrow();
                function slickArrow() {  
                    if(current_article==0){
                       $('.slick-prev').hide();
                    }else{
                       $('.slick-prev').show();
                    }
                    if (current_article==total_articles-3){
                        $('.slick-next').hide();
                    }else{
                        $('.slick-next').show();
                    }
                }
        };  
0

omg! Slick adds a special class for such arrows - slick-disabled. You need to disable infinite function and add a style for this class.

<script>
    $(document).ready(){
        $('#slider').slick({
            infinite : false, 
        });
    };
</script>
<style>
    .slick-arrow.slick-disabled { 
        display: none !important;
    }
</style>
1
  • Add some context to your code to help future readers better understand its purpose. Commented Jul 6, 2018 at 0:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.