How to detect screen size for responsive web design?

前端 未结 3 506
闹比i
闹比i 2021-02-05 21:22

I googled this and got a quirksmode site that gives you your screen size. Pulling up the console I see that screen.width and screen.height are directl

相关标签:
3条回答
  • 2021-02-05 22:00

    Take a look at Get the device width in javascript

    Media Queries work in js too:

    if (window.matchMedia('screen and (max-width: 768px)').matches) {}
    

    Another way would be:

    var width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
    
    0 讨论(0)
  • 2021-02-05 22:01

    This is what worked for me after long hunch. These attributes below provide responsive sizes based on new tab size.

    window.innerWidth
    window.innerHeight
    
    0 讨论(0)
  • 2021-02-05 22:17

    screen.width is the property your are looking for.

    0 讨论(0)
提交回复
热议问题