Answer the question
In order to leave comments, you need to log in
How to prevent following a link in OwlCarousel?
Hello!
I am using OwlCarousel as a slider. Each slide has a link like href="#". Clicking on the link opens a modal window.
If you do not manually flip through the slides, then clicking on the link does not scroll the page up and the window opens, everything is ok. But if you quickly flip the slide several times, and then click on the link, the modal window does not open and the page scrolls up.
It is interesting that this happens if the carousel is made infinite, i.e. she scrolls around. If you turn off infinite scrolling, then there is no such problem.
I am not strong in JS, with the help of Google I found that you can cancel the standard browser action using e.preventDefault (), I made this function:
$('a[class*="_toggler"]').click(function (e) {
e.preventDefault();
})
$('.owl-carousel').owlCarousel({
onDragged: callback
});
function callback(event) {
...
}
Answer the question
In order to leave comments, you need to log in
And why is it necessary to make the button a link if it just serves as a trigger, if you can put a button with the same styles and hang the opening of the modal by clicking on the button.
If you are using bootstrap, then you can open the modal programmatically like this:
$('#buttonID').click(function(){
$('#modalID').modal('show');
});
I would go into the carousel script and find the template output there and remove the link
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question