今天在做图片裁剪功能的时候,参考了下网友的资料,发现大家对图片宽度的获取方式不尽相同,于是详细整理下各个属性的区别(详细请参考MDN)。

1,HTMLImageElement.width是一个unsigned long 类型反映了 widthHTML 属性, 说明图像在CSS像素中渲染的宽度。

2,HTMLImageElement.naturalWidth返回一个 unsigned long 类型,表明图像在CSS像素中固有的宽度,如果可用的话; 否则, 返回0

3,Element.clientWidth 属性表示元素的内部宽度,以像素计。该属性包括内边距,但不包括垂直滚动条(如果有)、边框和外边距。该属性值会被四舍五入为一个整数。如果你需要一个小数值,可使用 element.getBoundingClientRect()方法返回元素的大小及其相对于视口的位置。")。

4,HTMLElement.offsetWidth 是一个只读属性,返回一个元素的布局宽度。一个典型的(译者注:各浏览器的offsetWidth可能有所不同)offsetWidth是测量包含元素的边框(border)、水平线上的内边距(padding)、竖直方向滚动条(scrollbar)(如果存在的话)、以及CSS设置的宽度(width)的值。

(知识)width、naturalWidth、clientWidth、offsetWidth区别整理的更多相关文章

  1. JS中关于clientWidth offsetWidth scrollWidth 的区别及意义

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

  2. JQuery中width和JS中JS中关于clientWidth offsetWidth scrollWidth 等的含义

    JQuery中: width()方法用于获得元素宽度: innerWidth()方法用于获得包括内边界(padding)的元素宽度: outerWidth()方法用于获得包括内边界(padding)和 ...

  3. clientWidth,offsetWidth,scrollWidth区别

    <html> <head> <title>clientWidth,offsetWidth,scrollWidth区别</title> </head ...

  4. H5,PC网页屏幕尺寸相关整理(scrollLeft,scrollWidth,clientWidth,offsetWidth)

    HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解scrollHeight: 获取对象的滚动高度. scrollLef ...

  5. JS中关于clientWidth offsetWidth scrollWidth 等的含义

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

  6. JS中关于clientWidth offsetWidth srollWidth等的含义

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

  7. js中的clientWidth offsetWidth scrollWidth等的含义

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

  8. clientWidth offsetWidth scrollWidth

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

  9. JS中关于clientWidth offsetWidth scrollWidth 等的含义的详细介绍

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

随机推荐

  1. HDU-4332-Constructing Chimney

    题目描述 用\(1*1*2\)的砖头摆出如图所示的烟囱,可以横着摆也可以竖着摆,求摆出\(n\)层高的烟囱会有多少种不同的方案. Input 一共有\(T\)组数据. 每组数据包含一个\(n(1 \l ...

  2. tp5框架用foreach循环时候报Indirect modification of overloaded element of think\paginator\driver\Bootst错误

    thinkphp5使用paginator分页查询数据后,需要foreach便利处理某一字段的数据,会出现类似题目的错误.主要是因为tp5使用分页类读取的数据不是纯数组的格式!所以在循环的时候需要用数据 ...

  3. 7.利用canvas和js画一个渐变的

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. Day03-jS

    javaScript概述 什么是javaScript:javaScript是一种直译式脚本语言.直接解释执行的语言. 什么是脚本语言? . java源代码--->编译成.class文件 ---& ...

  5. ajax跨域jsonp —— javascript

    目录 jsonp是什么 jsonp原理 原生js使用jsonp jquery使用jsonp jsonp是什么 jsonp作用:解决跨域问题 为什么有跨域问题? “同源策略限制了从同一个源加载的文档或脚 ...

  6. multipart/form-data提交

    pip install requests-toolbelt from requests_toolbelt import MultipartEncoder import requests m = Mul ...

  7. 基于双XCKU060+双C6678 的双FMC接口40G光纤传输加速计算卡

    基于双XCKU060+双C6678 的双FMC接口40G光纤传输加速计算卡 一.板卡概述 板卡采用基于双FPGA+双DSP的信号采集综合处理硬件平台,板卡大小360mmx217mm.板卡两片FPGA提 ...

  8. pycharm使用已经配置好的virtualenv环境

    前面已经介绍过基本的virtualenv使用方法,如想要了解的同学可以跳转https://www.cnblogs.com/weilijie/p/10964872.html 下面进入正题,我使用的是py ...

  9. Jmeter插件介绍

    JMeterPlugin可以把JMeter生成的jtl文件做出很好的统计图,同时还支持机器的cpu.memory.swap.disk io和network的监控. 插件可分四类: 用于服务器性能监视的 ...

  10. STL sort实现可迭代容器中对象的多重标准排序

    #include <iostream> #include <string> #include <vector> #include <algorithm> ...