Jquery 判斷滾動條到達頂部或底部 (可用於上拉下拉載入重新整理)
阿新 • • 發佈:2019-02-03
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>無標題頁</title>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(window).scroll(function() {
//$(document).scrollTop() 獲取垂直滾動的距離
//$(document).scrollLeft() 這是獲取水平滾動條的距離
if ($(document).scrollTop() <= 0) {
alert("滾動條已經到達頂部為0");
}
if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
alert("滾動條已經到達底部為" + $(document).scrollTop());
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 3000px; background-color: Blue;">
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>無標題頁</title>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(window).scroll(function() {
//$(document).scrollTop() 獲取垂直滾動的距離
//$(document).scrollLeft() 這是獲取水平滾動條的距離
if ($(document).scrollTop() <= 0) {
alert("滾動條已經到達頂部為0");
}
if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
alert("滾動條已經到達底部為" + $(document).scrollTop());
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 3000px; background-color: Blue;">
</div>
</form>
</body>
</html>