What's the difference between width, naturalWidth, and clientWidth?

偶尔善良 提交于 2020-02-01 05:04:09

问题


What is the difference between width, naturalWidth, and clientWidth?


回答1:


Read this:

Understanding offsetWidth, clientWidth, scrollWidth and -Height, respectively

example: <img> tag

naturalWidth: it is the original width of the image used in tag.

width: it is the value/default value of width attribute of tag.




回答2:


clientWidth represents the width of the element and is subject to manipulation by the browser. For example, a 300px wide image can be resized and this manipulated value will come through in clientWidth.

naturalWidth is the natural width of the element. In the example of a 300px wide image, the naturalWidth will still be 300 even if the image is resized in the browser via CSS or JavaScript.



来源:https://stackoverflow.com/questions/28167137/whats-the-difference-between-width-naturalwidth-and-clientwidth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!