Reputation: 17
I use this code on my site. I want to load this code only in a specific width of window. For example, in the less than 768 pixels, this script will no longer be called.
jQuery(document).ready(function() {
var owl = jQuery('.owl-carousel');
owl.owlCarousel({
rtl: true,
margin: 10,
nav: true,
loop: true,
responsive: {
0: {
items: 1
},
600: {
items: 3
},
1000: {
items: 5
}
}
})
})
Upvotes: 0
Views: 302
Reputation: 1806
You can use jQuery's width function and then do something like this:
jQuery(document).ready(function() {
if (jQuery( window ).width() > 768) {
/// your code here
}
});
Upvotes: 2
Reputation: 86
Try This
jQuery(document).ready(function() {
if ($(window).width() < 768){
var owl = jQuery('.owl-carousel');
owl.owlCarousel({
rtl: true,
margin: 10,
nav: true,
loop: true,
responsive: {
0: {
items: 1
},
600: {
items: 3
},
1000: {
items: 5
}
}
})
}
})
Upvotes: 0