A
A
Alexander Kokorin2021-09-16 08:55:26
JavaScript
Alexander Kokorin, 2021-09-16 08:55:26

How to highlight active custom link in OwlCarousel?

Good day.
Can someone help with selecting a custom link depending on whether the slide to which it leads is active.
There is no answer to this question on the Internet, there is only about slides.

By the way, there was a similar question on the forum, but there, again, they added a class to the active slide through this code:

$(function() {
  var owl = $(".owl-carousel");
  owl.owlCarousel({
    items: 4,
    dots: false,
    loop: true,
    margin: 10,
    slideBy: 1,
    URLhashListener: true,
    autoplayHoverPause: true,
    startPosition: "URLHash",
    onTranslate: function(e) {
      $(".owl-item").removeClass("highlighted");
    },
    onTranslated: function(e) {
      $(".owl-item").eq(e.item.index).addClass("highlighted");
    },
  });
});


Here is a link to that question - https://qna.habr.com/q/606046

These links are in this form:
<div class="">
  <a class="link" href="#zero">0</a>
  <a class="link" href="#one">1</a>
  <a class="link" href="#two">2</a>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daskus, 2021-09-16
@kokorinleks

If the number of links matches the number of slides, then you can slightly modify the example you have:
HTML code

<div class="target-links">
  <a class="link" href="#zero">0</a>
  <a class="link" href="#one">1</a>
  <a class="link" href="#two">2</a>
</div>

Javascript code
$(function() {
  var owl = $(".owl-carousel");
  owl.owlCarousel({
    items: 4,
    dots: false,
    loop: true,
    margin: 10,
    slideBy: 1,
    URLhashListener: true,
    autoplayHoverPause: true,
    startPosition: "URLHash",
    onTranslate: function(e) {
      $('.target-links .marked').removeClass('marked');
    },
    onTranslated: function(e) {
      $('.target-links .link').eq(e.item.index).addClass('marked');
    },
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question