offsetHeight/Width clientHeight/Width scrollHeight/Width等高宽算法

图解:
jquery里的对应取法: clientHeight/Width:innerHeight/Width(), offsetHeight/Width: outerHeight/Width().
window.innerHeight:窗口高度 window.outerHeight:浏览器高度
element.getBoundingClientRect(): 可以直接获取top/left/right/bottom/height/width等值,IE7以上都支持
element.offsetTop/offsetLeft: 如果父元素设置了postion(不为static),则取父元素外边框到本contentHeight中心点的值。如果父元素未设置,层层回溯到HTML外边框。 offsetLeft算法类似。
用法
移动端分页懒加载: 判断滚动条到了底部,自动触发下一页加载:监听scroll事件,判断clientHeight-scrollHeight<=0时,启动下一页加载。
img懒加载:
document.addEventListener('scroll',function(e){
var sid = setTimeout(function(e){
$('img').each(function(e){
if(this.dataset['isLazy']) return !0;
//在视窗且未懒加载过
if(this.scrollTop > this.offsetTop-window.innerHeight){
this.src=...;//加载图片
}else{
return !1;
}
});
}, 300);
});
offsetHeight/Width clientHeight/Width scrollHeight/Width等高宽算法的更多相关文章
- 关于height、offsetheight、clientheight、scrollheight、innerheight、outerheight的区别一览
平时,不管在pc端页面还是移动端页面,因为我们一般很少会设置某个块的的高度,但是呢,我有时候有需要取到这些高度以便于我们方便进行判断和下一步的编写.一般这个时候我都是直接的获取一个块的高度.heigh ...
- 关于height、offsetheight、clientheight、scrollheight、innerheight、outerheight的区别
二.也是平时经常用到的offsetheight 它返回的高度是内容高+padding+边框,但是注意哦,木有加margin哦,当然一般也木有啥需要把margin加进去的,以上代码为例,结果显示上图h2 ...
- js中offsetHeight、clientHeight、scrollHeight等相关属性区分总结
今天再次遇到了offset***.client***.scroll***的这三类属性的问题,总是混淆,现归纳总结如下: 大体上来说可以这样理解: client***属性(clientWidth.cli ...
- javascript - 所有的视图属性和方法(offsetHeight、clientHeight、scrollHeight、innerHeight等)
注意:本文只简单的介绍了各个视图的属性和方法.如果想要知道兼容性或者更多,请至文章底部参考链接处. 本文内容分为五大部分: Window视图属性 innerHeight 和 innerWidth ou ...
- offsetheight 和clientheight、scrollheight、scrollTop区别
clientHeight:元素客户区的大小,指的是元素内容及其边框所占据的空间大小(经过实践取出来的大多是视口大小) scrollHeight: 滚动大小,指的是包含滚动内容的元素大小(元素内容的总高 ...
- style.height、offsetHeight、clientHeight、scrollHeight的差别
style.height 包含元素的滚动栏,不包含边框 clientHeight 不包含元素的滚动栏和边框 offsetHeight 包含元素的滚动栏和边框 scrollHeight offsetHe ...
- clientWidth、clientHeight、offsetWidth、offsetHeight以及scrollWidth、scrollHeight
clientWidth.clientHeight.offsetWidth.offsetHeight以及scrollWidth.scrollHeight是几个困惑了好久的元素属性,趁着有时间整理一下 1 ...
- 各种高度的区别及height、clientHeight、scrollHeight、offsetHeight的区分
1.height.clientHeight.scrollHeight.offsetHeight 我们来实现test中的onclick事件 function justAtest() { ...
- offsetHeight, clientHeight与scrollHeight的区别
在网上搜了一下,结论非常笼统,讲IE从不讲版本,因此自己做了测试并上传结论.以下结论皆是在标准模式下测试通过的,没有测试quirk模式. clientHeight 大部分浏览器对 clientHe ...
随机推荐
- mac下安装git,并将本地的项目上传到github
mac下安装git 安装过程: 1.下载Git installer http://git-scm.com/downloads 2.下载之后打开,双击.pkg安装 3.打开终端,使用git --vers ...
- J2SE之基础语法总结一
1.标识符: (1)简单来说凡是可以起名字的地方都叫标识符,起标识符的时候要见名知意. (2)标识符由字母.数字.美元符$和下划线组成,标识符应以字母.下划线.$开头,注意不能以数字开头. (3)ja ...
- C#小知识点记录,对象的深拷贝
在CSDN中的定义是: public static string CompareExchange( ref string location1, string value, string compara ...
- hyper-v使用wifi链接网络
公司了给本屌一个thinkpad笔记本,10G内存.想不出拿来干什么...装了一个win8.1_64位,cf,qq,hyper-v. 昨天第一次玩hyper-v新建了的时候选择“第二代”坑爹就开始了, ...
- Java中遍历Map的常用方法
以下方法适用于任何map实现(HashMap, TreeMap, LinkedHashMap, Hashtable, 等等): 方式一(推荐): // 推荐 // 在for-each循环中使用entr ...
- Pycharm实用技巧汇总
Pycharm中输入 a = list 按住Command点鼠标左键,即可查看该类下的所有用法,如下图 获取类中有哪些成员
- object detection技术演进:RCNN、Fast RCNN、Faster RCNN
object detection我的理解,就是在给定的图片中精确找到物体所在位置,并标注出物体的类别.object detection要解决的问题就是物体在哪里,是什么这整个流程的问题.然而,这个问题 ...
- poj2100还是尺取
King George has recently decided that he would like to have a new design for the royal graveyard. Th ...
- 通过js来设置cookie和读取cookie,实现登陆时记住密码的功能
function setCookie(){ //设置cookie var loginCode = $("#login_code").val(); //获取用户名信息 var pwd ...
- jQuery库冲突解决办法
一次面试中面试官问到jQuery解决怎么冲突?虽然以前看过,但是我已经不记得了. 我的思路就是如果让我来设计,那我就用一个默认值$,不传参数,那就用$,最后就挂载在window.$上,传参数就用传入名 ...