Finding the Dimensions of the Window and Document - J Query

Problem
You want to get the width and height of the window and document in pixels.

Solution

jQuery’s width and height methods provide easy access to the basic dimensions of the window or document:

Discussion

It’s important to understand that the width and height of the document can (and likely will) be different from the width and height of the window. The dimensions of the window refer to the size of the view port—that portion of the browser that is available for displaying a document. The dimensions of the document refer to the size of the document itself. In most cases, the document height will be taller than the window’s height. The document’s width will always be at least the window’s width but may be greater than the window’s width. In Figure (The document size and the window size are often different),

The document size and the window size are  often different

jQuery('body').width() <jQuery(document).width(), and jQuery(document).width() == jQuery(window).width(). If the body were wider than the window, the document width would increase accordingly.
The width and height methods can also accept arguments if you want to set the dimensions of an element. The argument can be provided as an integer—in which case it will be interpreted as a pixel measurement—or as a string, in which case it is interpreted as a CSS-like measurement (i.e., $('#foo').width('300px')).


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

J Query Topics