简体   繁体   中英

Swiper slider custom prev/next navigation

I'm building wordpress site with swiper slider ( https://idangero.us/swiper/ ) listing portfolio items. What I need is next button that contains title of next slide. Is that possible? Something like this: rough preesentation

This is code:

var swiperOptions = {
    loop: true,
    speed: 1000,
}

function portfolioSlider() {
    var portfolioSlider = new Swiper('.js-portfolio-slider', swiperOptions);
    $(document).on('click', '.js-portfolio-slider__next', function(e) {
        e.preventDefault();
        portfolioSlider.slideNext();
    });
}

portfolioSlider();

See the documentation here: https://idangero.us/swiper/api/#events

portfolioSlider.on('transitionEnd', function() {
   var nextTitle = $('.swiper-slide-next').find('.title');
   if (nextTitle.length > 0) {
      $('.js-portfolio-slider__next').text(nextTitle);
   }
})

Should do the trick. The 'swiper-slide-next' should be the class of the next slide in your markup

Use swiper.slides[index + 1].innerText to get the inner content

Please refer to

penvar swiper = new Swiper('.swiper-container', {
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
});

console.log(swiper.slides[1].innerText) visit https://codepen.io/harmeet2harry/pen/qvQWyO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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