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 ...
随机推荐
- Jmeter之循环控制器
在使用Jmeter测试时,部分接口需要循环执行多次,这时候就可以使用循环控制器去控制执行. 循环控制器如下图: 说明 : (1.名称:标识,建议明确此循环控制器的使用的作用是什么(如:登录循环控制) ...
- C# Console.WriteLine堵塞进程
最近在项目中控制台为了调试使用Console.WriteLine(),发现在高并发的情况下会出现假锁状态,断点调试发现卡在Console.WriteLine那.需要进行一个键盘输入才可以继续. 关于C ...
- Apache hadoop namenode ha和yarn ha ---HDFS高可用性
HDFS高可用性Hadoop HDFS 的两大问题:NameNode单点:虽然有StandbyNameNode,但是冷备方案,达不到高可用--阶段性的合并edits和fsimage,以缩短集群启动的时 ...
- nslookup、dig、host
1.作用:查询域名对应的地址或者地址对应的域名 2.nslookup已经不建议使用,慢慢就会废弃,建议使用dig和host代替 3.格式 dig: dig @NameServer 域名 Type ho ...
- HTML5——新表单元素 表单属性 语义元素
表单元素 新的表单元素 datalist——输入域选项列表 keygen——提供一种验证用户的可靠方法 output——不同类型的输出,比如计算或脚本输出 表单属性 <form> / &l ...
- ionic3构建过程中遇到的找不到AndroidManifest.xml的问题
问题如下: Failed to install 'ionic-plugin-keyboard': Error: ENOENT: no such file or directory, open '/Us ...
- 使用Inception-v3进行图像分类
https://blog.csdn.net/sinat_27382047/article/details/80534234 https://www.jianshu.com/p/cc830a6ed54b ...
- 【监控笔记】【2.4】SQL Server中的 Ring Buffer 诊断各种系统资源压力情况
SQL Server 操作系统(SQLOS)负责管理特定于SQL Server的操作系统资源. 其中相关的动态管理试图sys.dm_os_ring_buffers将被标识为仅供参考.不提供支持.不保证 ...
- Spring框架学习总结
一.Spring概述 1.什么是Spring? Spring是一个优秀轻量级的框架,是Java中使用最多的框架,Spring框架具有轻量.控制反转.面向切面.容器.框架.MVC的特点. 2.Sprin ...
- Java数据结构之栈(Stack)
1.栈(Stack)的介绍 栈是一个先入后出(FILO:First In Last Out)的有序列表. 栈(Stack)是限制线性表中元素的插入和删除只能在同一端进行的一种特殊线性表. 允许插入和删 ...