基于jQuery实现滚动刷新效果
(编辑:jimmy 日期: 2025/10/25 浏览:3 次 )
Jquery实现简单的滚动刷新效果:
实际情况使用Ajax获取后台数据更新前端页面即可实现页面滚动刷新效果
HTML正文:
<form id="form1" runat="server"> <div style="height: 3000px; background-color: yellow;"> </div> </form>
Javascript操作代码:
$(document).ready(function() {
$(window).scroll(function() {
//$(document).scrollTop() 获取垂直滚动的距离:最小值为0,最大值:文档高度-可视化窗口高度
//$(document).scrollLeft() 这是获取水平滚动条的距离
console.log("垂直滚动条位置:"+$(document).scrollTop()+"--"+$(window).height());
if ($(document).scrollTop() <= 0) {
console.log("滚动条已经到达顶部为0");
}
/**
*$(document).height():文档的高度
*$(window).height():可视域的高度:窗口的大小:根据浏览窗口的大小变化
*判断底部:文档高度<=滚动条垂直高度+可视窗口的高度
* */
if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
console.log("滚动条已经到达底部为" + $(document).scrollTop());
}
});
});
效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇:用jQuery实现优酷首页轮播图
