Answer the question
In order to leave comments, you need to log in
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");
},
});
});
<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
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>
$(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 questionAsk a Question
731 491 924 answers to any question