html中滚动条的监听
来源:互联网 发布:淘宝店铺门头图片 编辑:程序博客网 时间:2024/05/22 04:49
html中滚动条的监听
在很多的商品类网页的DOM加载顺序中,商品不是一次性加载完成的,而是用户在滑动滚动条的时候,js代码根据用户的滑动滚动条的距离来确定的,下面我们来写一个最简单的监听实例
<!DOCTYPE html><html><head> <title>简单监听滚动条</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <style type="text/css"> #main { margin: 0 auto; width: 100%; } ul { margin: 0; padding: 0; } ul li { list-style-type: none; margin: 0; margin-top: 20px; text-align: center; } </style></head><body><div id="main"> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> <li>10</li> <li>11</li> <li>12</li> <li>13</li> <li>14</li> <li>15</li> <li>16</li> <li>17</li> <li>18</li> <li>19</li> <li>20</li> <li>21</li> <li>22</li> <li>23</li> <li>24</li> <li>25</li> <li>26</li> <li>27</li> <li>28</li> <li>29</li> <li>30</li> </ul></div><script type="text/javascript"> /* * 利用原生的javascript来监听网页的滚动条 */ window.onscroll = function () { //htmlHeight 是网页的总高度 var htmlHeight = document.body.scrollHeight || document.documentElement.scrollHeight; //clientHeight是网页在浏览器中的可视高度, var clientHeight = document.body.clientHeight || document.documentElement.clientHeight; //scrollTop是浏览器滚动条的top位置, var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; //通过判断滚动条的top位置与可视网页之和与整个网页的高度来返回各项参数 if (scrollTop + clientHeight == htmlHeight) { alert("htmlHeight:" + htmlHeight + "clientHeight" + clientHeight + "srolltop" + scrollTop); } }</script></body></html>
0 0
- html中滚动条的监听
- html中滚动条的样式
- HTML中滚动条的样式设置
- 滚动条的监听事件。
- HTML中除去滚动条
- html中div滚动条
- 在HTML中创建带滚动条的table
- html中如何去掉浏览器右边的滚动条
- 监听滚动条js的操作
- 监听滚动条事件
- 监听滚动条事件
- HTML中滚动条代码及属性
- html中滚动条属性设置
- html在文本框中加入滚动条
- html中滚动条属性设置
- html中滚动条属性设置
- html中滚动条属性设置
- HTML中滚动条属性相关设置
- poj1852Ants
- [Oracle数据库] 深入分析ora-600 2662错误系列一
- 通俗的例子去理解BP网络
- 【杭电】[2015]偶数求和
- Scala 泛型
- html中滚动条的监听
- 绑定UI使用说明
- Effective C++ 笔记目录
- springmvc(一) 入门程序
- SDN
- PHP 7 值得期待的新特性(上)
- ExtJs checkboxgroup选择事件
- listbox和comebox添加图片
- 基于cuda的gpu加速