Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在100%缩放时获得DIV的大小?_Javascript_Html_Size_Zooming - Fatal编程技术网

Javascript 如何在100%缩放时获得DIV的大小?

Javascript 如何在100%缩放时获得DIV的大小?,javascript,html,size,zooming,Javascript,Html,Size,Zooming,如果一个网页在任何现代浏览器中被放大/缩小,那个么我怎样才能在100%放大时找到DIV元素的大小呢 编辑:我在这里问了另一个问题,但没有回答。你知道原来的尺寸吗?至少在IE7+中,您可以计算出缩放级别和比例: zoomLevel = Math.round((self.document.body.parentElement.offsetWidth / self.document.body.offsetWidth) * 100); 你知道原版的尺寸吗?至少在IE7+中,您可以计算出缩放级别和比例:

如果一个网页在任何现代浏览器中被放大/缩小,那个么我怎样才能在100%放大时找到DIV元素的大小呢


编辑:我在这里问了另一个问题,但没有回答。

你知道原来的尺寸吗?至少在IE7+中,您可以计算出缩放级别和比例:

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

你知道原版的尺寸吗?至少在IE7+中,您可以计算出缩放级别和比例:

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

如果您使用的是jQuery,那么可以使用$'div'.width或$'div'.outerWidth方法很容易地找到它。其他JS库中也有类似的方法,所以只要问问您是否想知道所选框架中的方法

如果您使用的是jQuery,您可以使用$'div'.width或$'div'.outerWidth方法轻松找到它。其他JS库中也有类似的方法,因此只要询问您是否想了解所选框架中的方法

您可以使用纯JavaScript获得宽度和高度,如下所示:

// 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');

使用jQuery或任何其他库也可以做同样的事情,这样通常更快、更简单。

您可以使用纯JavaScript获得宽度和高度,如下所示:

// 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');

使用jQuery或任何其他库也可以做同样的事情,这样做通常更快、更简单。

还可以看到:还可以看到:如果页面被放大/缩小,这将不起作用。请参阅问题中的“我的编辑”。如果页面被放大/缩小,则此操作无效。请参见问题中的“我的编辑”。