How to disable javascript for responsive design

前端 未结 6 736
北恋
北恋 2020-12-15 12:15

I have been using supersized jQuery for the slideshow background of my website. I am making the website responsive and using css media queries.

I would like to be a

6条回答
  •  攒了一身酷
    2020-12-15 12:45

    As others mentioned, there are plenty of jQuery plugins you can use. However, if all you want to use is just plain vanilla jQuery you can also do what you want.

    You can use the resize method in jquery to detect the size of the window.

    $(window).resize(function() {
       if ($(this).width() > 480) {
          // call supersize method
       }
    });
    

    Then on doc ready, just be sure to call the resize window so it will initially call or not call the method depending on your window's current size:

    $(document).ready(function() {
       $(window).resize();
    });
    

    PS > If you do not need this script to run every time the window resizes, but rather only when it reaches below 480 pixels, slight modifications can be made to unbind the resize method after your script needs to be disabled or enabled.

提交回复
热议问题