javascript – Use jQuery function only on @media screen and (max-width:960px)

Question:

We know that @media queries exist.

They work with CSS.

But I need to do it with JavaScript.

I need bxSlider to work only on @media screen and (max-width:960px) .

Answer:

So guys, I did it as follows and solved my problem:

jQuery(document).ready(function() {
   if( $(window).width() <= 960){
     jQuery('.img-parceiros').bxSlider({
        nextSelector: '.seta-dir',
        prevSelector: '.seta-esq',
        nextText: '',
        prevText: '',
        auto: false,
        slideWidth: 200,
        minSlides: 2,
        maxSlides: 2,
        pager:false
     });
   }
});
Scroll to Top