S
S
Serqwezxc2021-07-01 00:07:32
JavaScript
Serqwezxc, 2021-07-01 00:07:32

How to change slick slider caption text when swiping a slide?

There is js in which the slide counter works. When you swipe to the next slide, new text is added. Question: how to change the text again, when swiping back?

<span class="name-itm">Текст</span>

var $slider = $('.slider');
var sliderCounter = document.getElementsByClassName("slider-counter");
var nameItm = document.getElementsByClassName("name-itm");
var newText = "Новый текст";

if ($slider.length) {
    var updateSliderCounter = function(slick, currentIndex) {
        currentSlide = slick.slickCurrentSlide() + 1;
        $(sliderCounter).text(currentSlide);
      };
      $slider.on('afterChange', function(event, slick, currentSlide, nextSlide) {
        updateSliderCounter(slick, currentSlide, nextSlide);
    nextSlide = newText;
        $(nameItm).text(nextSlide);
     });
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kryamk, 2021-07-02
@kryamk

I wrote such garbage, it works if there are three or more slides

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question