How to disable javascript for responsive design

前端 未结 6 734
北恋
北恋 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:36

    You can detect the screen width with JavaScript, using screen.width, and then determine what you want to do from there.

    if(screen.width < 480) { 
        // do any 480 width stuff here, or simply do nothing
        return;
    } else {
        // do all your cool stuff here for larger screens
    }
    

    Wrap all of your animations and all the code you don't want to run inside the else block for cases where the screen size is less than 480.

    As a word of caution, IE tends to do things different, and I don't have IE to test, so you may want to run screen.width there and adjust for any differences, if necessary. But in Chrome, screen.width returns 1280, which is the correct width for my screen.

提交回复
热议问题