HTML页面滑动到最底部触发事件
其实基本原理做一个判断,如果 页面总高度 = 视口高度 + 浏览器窗口上边界内容高度 ,那么就是把页面滑动到了最低部,然后执行一个事件。
//要触发的事件(自己定义事件的内容)
function ajax_function() {
window.location.href = 'http://baidu.com';
}
var timeoutInt; // 要保证最后要运行一次
// window.onscroll窗口添加滚动条事件
window.onscroll = function () {
setTimeout(function () {
if (timeoutInt != undefined) {
window.clearTimeout(timeoutInt);
}
timeoutInt = window.setTimeout(function () {
//监听事件内容
if(getScrollHeight() == getDocumentTop() + getWindowHeight()){
//当滚动条到底时,这里是触发内容
//异步请求数据,局部刷新dom
ajax_function()//调用上面自定义的事件函数。
}
}, 105);
}, 100);
}
//(浏览器窗口上边界内容高度)
function getDocumentTop() {
var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
if (document.body) {
bodyScrollTop = document.body.scrollTop;
}
if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
console.log("scrollTop:"+scrollTop);
return scrollTop;
}
//可视窗口高度(屏幕可以看见的高度)
function getWindowHeight() {
var windowHeight = 0;
if (document.compatMode == "CSS1Compat") {
windowHeight = document.documentElement.clientHeight;
} else {
windowHeight = document.body.clientHeight;
}
console.log("windowHeight:"+windowHeight);
return windowHeight;
}
//滚动条滚动高度(即整个网页的高度)
function getScrollHeight() {
var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
if (document.body) {
bodyScrollHeight = document.body.scrollHeight;
}
if (document.documentElement) {
documentScrollHeight = document.documentElement.scrollHeight;
}
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
console.log("scrollHeight:"+scrollHeight);
return scrollHeight;
}
HTML页面滑动到最底部触发事件的更多相关文章
- js 滚动条滚动到底部触发事件
一.前言 在开发项目时,常常需要展示大量数据.如果全部显示出来,数据相对少时,看不出来什么不同,如果数据很多时,一次请求全部显示,这就相当可怕了. 面对这种问题,PC里使用了分页效果,将数据分成一页页 ...
- asp.net页面关闭的时候如何触发事件?
<script type="text/javascript"> var pb_strConfirmCloseMessage; var pb_blnCloseWind ...
- $(window).scroll在页面没有滚动条时无法触发事件的bug解决方法
JS //给页面绑定滑轮滚动事件 if (document.addEventListener) { //webkit document.addEventListener('mousewheel', s ...
- js滚动条滚动到底部触发事件
$("#contain").scroll(function(){ var $this =$(this), viewH =$(this).height(),//可见高度 conten ...
- js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的
js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的 相信很多人都见过瀑布流图片布局,那些图片是动态加载出来的,效果很好,对服务器的压力相对来说也小了很多 有手机的相信都见过这样 ...
- jQuery 滚动条 滚动到底部(下拉到底部) 加载数据(触发事件、处理逻辑)、分页加载数据
1.针对浏览器整个窗口滚动 主要代码: <script type="text/javascript"> ; function GetProductListPageFun ...
- scroll 滚动到指定位置触发事件 and 点击一按钮/链接让页面定位在指定的位置
scroll 滚动到指定位置触发事件:$(function(){ $(window).scroll(function() { var s =$(window).scrollTop(); if (s&g ...
- 点击 a 标签触发事件而不跳转页面
有时候需要让 a 标签像 button 一样,被点击的时候触发事件而不跳转页面. <html> <body> <a id="a1" href=&quo ...
- html5与js关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的value点击全选状态onclick="select();"。做购物车页面时会要用到。
关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的点击全选状态onclick="s ...
随机推荐
- robotframework json解析
用robotframework做接口测试,现在用的最多的就是json格式的数据,刚开始接触会感觉一脸懵逼,不知道怎么去取里面的值.在这里简单介绍一下,其实本身json取值不会太难,只要理解层次关系,一 ...
- 【SpringMVC】---搭建框架步骤
项目如下 一.加入 Jar 包 部分jar包可以不导(第4.9.11个可以不导入) 二.在 Web.xml 中配置 DispatcherServlet <?xml version="1 ...
- NeDB——node嵌入式数据库
参考资料1:[http://www.alloyteam.com/2016/03/node-embedded-database-nedb/] 参考资料2:[https://github.com/loui ...
- web form 防止一个请求重复提交
/// <summary> /// 防止一个请求重复提交 /// </summary> public void PreventRepeatSubmit() { if (Scri ...
- 【Qt开发】【VS开发】【Linux开发】OpenCV、Qt-MinGw、Qt-msvc、VS2010、VS2015、Ubuntu Linux、ARM Linux中几个特别容易混淆的内容
[Qt开发][VS开发][Linux开发]OpenCV.Qt-MinGw.Qt-msvc.VS2010.VS2015.Ubuntu Linux.ARM Linux中几个特别容易混淆的内容 标签:[Qt ...
- django groupby 用法
- django F和Q 关键字使用
F 的使用: 想给表里每个价格加上一百就要用上F,直接加是不行的.
- 【Linux命令】解压相关命令
xxx.tar.gz : tar xvzf xxx.tar.gz xxx.tar.bz2 : tar -vxjf xxx.tar.bz2
- STM32f103软件复位
参考博客: http://bbs.21ic.com/icview-1251690-1-1.html stm32f103rct 软件复位函数: 在core_cm3.h文件 static __INLINE ...
- c++多线程并发学习笔记(1)
共享数据带来的问题:条件竞争 避免恶性条件竞争的方法: 1. 对数据结构采用某种保护机制,确保只有进行修改的线程才能看到修改时的中间状态.从其他访问线程的角度来看,修改不是已经完成了,就是还没开始. ...