今天在做图片裁剪功能的时候,参考了下网友的资料,发现大家对图片宽度的获取方式不尽相同,于是详细整理下各个属性的区别(详细请参考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. Luogu P3953 [NOIP2017]逛公园

    题目 首先我们跑出从\(1\)出发的最短路\(d1\)和反图上从\(n\)出发的最短路\(dn\). 然后我们处理出长度不超过\(d1_n+k\)的最短路边集,给它拓扑排序. 如果存在环,那么这个环一 ...

  2. Codeforces - 1203D2 - Remove the Substring (hard version) - 双指针

    https://codeforces.com/contest/1203/problem/D2 上次学了双指针求两个字符串之间的是否t是s的子序列.但其实这个双指针可以求出的是s的前i个位置中匹配t的最 ...

  3. 07.AutoMapper 之列表和数组(Lists and Arrays)

    https://www.jianshu.com/p/419a3b7f12d5 列表和数组(Lists and Arrays) AutoMapper只需要配置元素类型的映射配置,不需要针对列表和数组进行 ...

  4. handlebars杂记

      1.{{{caption}}}三个花括号,可以解析 空格 变成 ‘空格’.   2.数据是posts:[{  }]数组时候,可以用{{posts.length}}取得其数组长度   3.handl ...

  5. VMware 问题

    桥接模式下,小鸡上不了网问题 多网卡导致的问题 解决:编辑-虚拟网络编辑器 选择vmnet0,然后点击右下角更改设置 把自动改为指定要桥接的网卡,然后点击确定,测试看看.

  6. linux编译安装mysql5.7

    一.下载源码包 -src cd /usr/local/src/mysql--src wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5 ...

  7. PAT Advanced 1033 To Fill or Not to Fill (25 分)

    With highways available, driving a car from Hangzhou to any other city is easy. But since the tank c ...

  8. 用jmeter进行接口测试(2)

    1.jmeter配置元件之HTTP信息头管理器使用   右击线程组-[添加]-[HTTP信息头管理器] 是打发  Jmeter请求元件之参数化txt

  9. php判断变量是否为数字is_numeric()

    is_numeric — 检测变量是否为数字或数字字符 <?php $tests = array( "31", 1380, "1e4", "no ...

  10. php扩展安装,指定新的openssl

    1 自己从源码编译一个新的openssl 下载源码下来解压到 /mnt/soft/openssl-1.0.2m (openssl 安装到) ./config -h /usr/bin/perl ./Co ...