omid chahardoli
omid chahardoli

Reputation: 17

called a jQuery function only over a specific width of window

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

Answers (3)

Edwin Krause
Edwin Krause

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

.width() Refernece

Upvotes: 2

Rubix's Mind
Rubix's Mind

Reputation: 74

if ($( window ).width() > 768){//ur code}

Upvotes: 0

Vinee
Vinee

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

Related Questions