0
votes

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();
2

2 Answers

1
votes

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

0
votes

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