这是我的视图代码,我使用了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>在scroll事件脚本中,我需要找出垂直滚动的最大值是什么,所以我得到了容器out -Height,但它不是最大值,它比1280x1024屏幕分辨率下的796px大,在不同的屏幕分辨率设置中可能会有所不同。我需要一些帮助,而不是"796“的号码。
发布于 2011-05-17 14:56:47
尝试:
$("#container").attr({ scrollTop: $("#container").attr("scrollHeight") });从JQuery 1.9.1开始,您将需要:
$("#container").scrollTop($("#container").prop("scrollHeight"));发布于 2013-02-17 17:59:01
发布的答案不正确;scrollTop的最大值不是scrollHeight,而是scrollHeight - outerHeight。
这将为您提供正确的值:
var elem = $("#container");
var maxScrollTop = elem[0].scrollHeight - elem.outerHeight();发布于 2012-03-20 16:37:45
在不使用jQuery的情况下实现这一点的最佳方法。
document.getElementById('container').scrollTop = document.getElementById('container').scrollHeight;使用jQuery对我不起作用,所以如果在上面有问题的话,试试这个。
https://stackoverflow.com/questions/6027278
复制相似问题