Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iDangerous Swiper - hide navigation arrows from first and last slide

Using iDangerous Swiper how do you target and hide the .left-arrow class of the first slide? There is this in the documentation - mySwiper.getFirstSlide() - returns first slider slide (slide instance) but how do you indicate that when on this slide hide the left arrow?

Not handy with js but I've tried things like this with no success:

mySwiper.getFirstSlide({
  $(this).find('.left-arrow').hide(),
});

var firstSlide = mySwiper.getFirstSlide();
firstSlide.find('.left-arrow').hide();

This probably needs to be a conditional statement - if it's the first slide then hide the left arrow else show it. I'm just not sure how to set something like that up. Any help is appreciated. Thanks.

http://codepen.io/NewbCake/pen/sIbxi

like image 348
NewbCake Avatar asked Feb 14 '23 22:02

NewbCake


2 Answers

It's much easier than you think, specially if you're not handy with JS, considering you could solve this with pure CSS.

Swiper assigns a CSS class named ".swiper-button-disabled" to the first and last arrow, to make sure the swiper doesn´t move any further. Try this:

.left-arrow.swiper-button-disabled {opacity: 0;}
like image 195
Ronald Méndez Avatar answered Feb 17 '23 03:02

Ronald Méndez


var howManySlides = $('.swiper-wrapper .swiper-slide').length - 1;
$(".arrow-left").addClass('hide');
var mySwiper = new Swiper('.swiper-container',{
    loop:false,
    onSlideChangeStart: function(){
        $(".tabs .arrow-left,.tabs .arrow-left").removeClass('hide');
        if(tabsSwiper.activeIndex === 0) {
            $(".tabs .arrow-left").addClass('hide');
        }
        if(tabsSwiper.activeIndex === howManySlides) {
            $(".tabs .arrow-right").addClass('hide');
        }
    }
})
like image 42
yurij Avatar answered Feb 17 '23 04:02

yurij