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 ...
随机推荐
- Unity Audio Source Properties
Audio Clip 音频剪辑 将播放声音的剪辑文件 Mute 静音 Bypass Effects 直通效果 应用音频源的快速“直通”过滤效果.一个简单的方法来打开/关闭所有特效 Output 产量 ...
- DedeCMS调取其他织梦CMS站点数据库数据方法
第1步:打开网站include\taglib文件夹中找到sql.lib.php文件,并直接复制一些此文件出来,并把复制出来的这个文件重命名为mysql.lib.php.注:mysql.lib.php, ...
- 用matplotlib对数据可视化
下图是要用到的数据集,反映了从1984到2016年的失业率的变化 1.导入可视化模块import matlibplot.pyplot as plt, 函数plt.plot(x, y)确定折线图的点,x ...
- 关于BeautifulSoup4 解析器的说明
一.解析器概述 如同前几章笔记,当我们输入: soup=BeautifulSoup(response.body) 对网页进行析取时,并未规定解析器,此时使用的是python内部默认的解析器“html. ...
- 使用itchat完成微信自动回复
import itchat from itchat.content import * # 微信自动回复 @itchat.msg_register([TEXT]) def text_reply(msg) ...
- python+selenium操作cookie
WebDriver提供了操作Cookie的相关方法,可以读取.添加和删除cookie信息. WebDriver操作cookie的方法: get_cookies(): 获得所有cookie信息. get ...
- selenium学习-对当前浏览器窗口截屏
方法:get_screenshot_as_file(filename) # coding=UTF-8 #16.对当前浏览器窗口截屏 import sys reload(sys) sys.setdefa ...
- APIView的流程分析
APIView的流程分析 1.入口,因为视图类的继承APIView()的 as_view()是一个绑定类的方法 2.进入as_view(),正好这个as_view()有个返回值 返回的是dispat ...
- Jmeter响应数据显示乱码问题
Jmeter在访问接口的时候,响应内容如果有中文可能会显示乱码,原因应该是响应页面没有做编码处理,jmeter默认按照ISO-8859-1编码格式进行解析. 解决步骤: 现象:jmeter访问本地文件 ...
- Linux 系统多台主机之间做SSH免密码登陆
SSH 免密登录 环境说明 CentOS 7.3 关键点 免密登录的关键点在于理解谁登录谁. A 生成的公钥给 B,也给 C.D,则 A 可以直接免密 SSH 登录 B.C.D A 生成密钥 在 A ...