javascript - Jquery get consistent width using document body -


I want to get the width of a web page and found that $ (window) Width () does not return a corresponding value due to the width of the scrollbar, depending on the browser and whether the scrollbar is visible

instead of window I am getting width of the document body :

  $ ('body'). InnerWidth ()  

The correct value returns when the test is done Anyone using this approach has any problem?

In the body setting {width: 100%;}. You may need to put that code in $ (document) .ready (function () {}); There is a problem getting the DOM element size in callback or in a short timeout, before you can calculate it in its final state, then you can get the shape after it. Although the correct width appears instantly, there may also be a few milliseconds, where it has not been calculated.

Hope that helps.


Comments

Popular posts from this blog

c++ - C/pp Sockets, recv()/send() works only under gdb -

GO: Serve static pages -

objective c - How to open front/back camera at the same time in iOS developing? -