简体   繁体   中英

how to get size of DIV at 100% zoom?

If a web page is zoomed out/in in any modern browser, then how I can find size of a DIV element at 100% zoom?

EDIT:: I asked another similar question here, which was unanswered.

Do you know the original size? At least in IE7+ you can figure out zoom level and figure out the proportions:

zoomLevel = Math.round((self.document.body.parentElement.offsetWidth / self.document.body.offsetWidth) * 100);

If you're using jQuery, you can use the $('#div').width() or $('#div').outerWidth() method to find it very easily. There are equivalents in other JS libraries, so just ask if you want to know the method in your framework of choice

You can use pure JavaScript to get the width and height like so:

// Create an object of the div.
var divElement = document.getElementById('id of div');

// Retrieve the height and width.   
var width = divElement.getAttribute('width');
var height = divElement.getAttribute('height');

It's possible to do the same thing with jQuery or any other library and it's generally faster and easier that way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM