<span style="font-size:18px;"><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>jquery scrollTop</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body style="height: 2000px;">
<div id="topData" class="howHeight" style="height: 35px;position: fixed;top:0;left: 0;right:0;margin: auto;background: black;color: white;font: 25px/35px '微软雅黑';text-align: center;">document.height():<b></b>px;window.height():<b></b>px;<span>距离顶部</span><b>0</b>px</div>
<script src="../jquery1.js"></script>
<script>
$(function(){
$(document).scroll(function(){
var dHeight=$(document).height();
var wHeight=$(window).height();
var scrollTop=$(document).scrollTop();
$("#topData b").first().text(dHeight).end().eq(1).text(wHeight).end().last().text(scrollTop);
});
$(document).trigger('scroll');
});
</script>
</body>
</html>
</span>
我们可以发现:
当滚动条到达底部时候 document.height()=window.height()+document.scrollTop();所以,只要判断这个式子是否成立,就可以确定滚动条是否到达底部。
jquery判断滚动条到达底部的方法
最新推荐文章于 2022-10-11 09:24:06 发布