Why is the window.width smaller than the viewport width set in media queries

后端 未结 7 2027
轻奢々
轻奢々 2020-12-01 09:45

I am quite puzzled and still unsure how to explain this in proper words. So far i\'ve used and set up my media queries with Breakpoint. An used Breakpoint-variable looks lik

7条回答
  •  眼角桃花
    2020-12-01 10:07

    Use classes on body to define if you are on mobile, tablet or desktop instead using pixels.

    For me it did not work document.body.clientWidth or innerWidth. My functionality crashes between 1023-1040px even if my js code must do this statement:

    if($(window).width()<1024)
    

    The solution was to put on body a new class for less than 1024 and name it "small-res" and use it than in my code instead of pixels verification:

    if($(body).hasClass('small-res')) 
    

    I recommend it to you too.

提交回复
热议问题