Answer the question
In order to leave comments, you need to log in
OwlCarousel first version. How to change the speed to a variable?
Greetings dear members of the forum. Sorry if the question is stupid. Do not judge strictly, I am just starting to get acquainted with JS. I need to take out the speed into a variable and change it depending on the screen width. There is such a design. Explain to the noob why it doesn't work and how to fix it. I understand that the width variable is outside the scope of the owl function, but I have no idea how to fix it.
$(document).ready(function() {
var width = $(window).width()
if (width > 768){
var speed = 1500
} else {
var speed = 300
}
var owl = $(".sldr").owlCarousel({
slideSpeed : speed
});
});
Answer the question
In order to leave comments, you need to log in
$(document).resize(function() {
$(".sldr").owlCarousel({
slideSpeed : $(window).width() > 768 ? 1500 : 300
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question