牛叔叔 的笔记

好好学习

2019-10-22 08:39

js判断滚动到屏幕底部

牛叔叔

WEB前端

(976)

(0)

收藏


页面元素offset共有5个平面属性:


  1. offsetParent
  2. offsetTop
  3. offsetLeft
  4. offsetWidth
  5. offsetHeight

offsetWidth与offsetHeight

也就是元素的可视宽度,这个宽度包括元素的边框(border),水平padding,垂直滚动条宽度,元素本身宽度等

offsetWidth=(border-width)*2+(padding-left)+(width)+(padding-right)。offsetHeight=(border-width)*2+(padding-top)+(height)+(padding-bottom)

offsetLeft与offsetTop

返回对象元素边界的左上角顶点相对于offsetParent的左上角顶点的水平偏移量。从这个定义中我们可以明确地知道offsetLeft与当前元素的margin-left和offsetParent的padding-left有关

offsetLeft=(offsetParent的padding-left)+(中间元素的offsetWidth)+(当前元素的margin-left)。offsetTop=(offsetParent的padding-top)+(中间元素的offsetHeight)+(当前元素的margin-top)

offsetParent

  1. 如果当前元素的父级元素没有进行CSS定位(position为absolute或relative),offsetParent为body。

  2. 如果当前元素的父级元素中有CSS定位(position为absolute或relative),offsetParent取最近的那个父级元素。

滚动条到底部的条件即为scrollTop + clientHeight == scrollHeight。


						

0条评论

点击登录参与评论