N
N
nfobdw1432015-08-17 12:48:19
JavaScript
nfobdw143, 2015-08-17 12:48:19

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       
    });     
});

UPD: The option works. I forgot that the variable needs to be redefined when resizing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-08-17
@nfobdw143

$(document).resize(function() {
    $(".sldr").owlCarousel({
        slideSpeed :  $(window).width() >  768 ? 1500 : 300     
    });     
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question