[英]getting the maximum value of vertical scroll using jquery
這是我的視圖代碼我使用jquery它工作,我沒有任何問題,直到我更改它停止工作的屏幕分辨率。 我知道問題在哪里,但我無法解決它看代碼:
@model PNUBOOKIR.Models.ProductModels
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<script src="@Url.Content("~/Scripts/jquery.js")" type="text/javascript"></script>
<script type="text/javascript">
var endRun = false;
var PageNO = 1;
$(window).scroll(function () {
if ((($("#container").outerHeight() - 796) == ($(this).scrollTop())) && (!endRun)) {
endRun = true;
Load();
}
});
$(document).ready(function () {
Load();
return false;
});
function Load() {
var BtnShowMore = document.getElementById("BtnShowMore");
BtnShowMore.innerHTML = "Loading...";
$.ajax({ type: "Post",
url: "Product" + "/" + "GetHomeEventAjax",
data: "{" + "PageNO" + ":" + PageNO + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function succ(data, states) {
if (states == "success") {
if (data.Content != null) {
var EventListArea = document.getElementById("result");
$('#result > tbody:last').append(data.Content);
PageNO = PageNO + 50;
BtnShowMore.innerHTML = "More";
endRun = false;
}
else BtnShowMore.innerHTML = "Loading is complete";
}
},
error: function err(result) { alert(result.responseText); }
});
}
</script>
</head>
<body>
<div id="container">
<table cellpadding="4" cellspacing="2" border="1" style="width: 450px; direction: rtl;"
id="result">
<tbody>
<tr>
<th>کد کالا</th>
<th>نام کتاب</th>
<th>ناشر</th>
</tr>
</tbody>
</table>
<a style="width: 200px" id="BtnShowMore">
Load</a>
</div>
</body>
</html>
在滾動事件腳本中,我需要找出垂直滾動的最大值是什么,所以我得到容器外部 - 高度但不是最大值它比它在1280x1024屏幕分辨率中大796px它可以是不同的在不同的屏幕分辨率設置。 我需要一些幫助而不是“796”號。
發布的答案不正確; scrollTop
的最大值不是scrollHeight
,它是scrollHeight - outerHeight
。
這將為您提供正確的值:
var elem = $("#container");
var maxScrollTop = elem[0].scrollHeight - elem.outerHeight();
嘗試:
$("#container").attr({ scrollTop: $("#container").attr("scrollHeight") });
從JQuery 1.9.1開始,您將需要:
$("#container").scrollTop($("#container").prop("scrollHeight"));
沒有jQuery的最佳方法。
document.getElementById('container').scrollTop = document.getElementById('container').scrollHeight;
使用jQuery它不適合我,所以如果有上面的問題嘗試這個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.