使用jquery获取垂直滚动的最大值

这是我的视图代码我使用jquery它工作,我没有任何问题,直到我更改它停止工作的屏幕分辨率。 我知道问题在哪里,但我无法解决它看代码:

@model PNUBOOKIR.Models.ProductModels @{ Layout = null; }    Index   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); } }); }    
کد کالا نام کتاب ناشر
Load

在滚动事件脚本中,我需要找出垂直滚动的最大值是什么,所以我得到容器外部高度,但不是最大值,它比1280×1024屏幕分辨率大796px它可以是不同的在不同的屏幕分辨率设置。 我需要一些帮助,而不是“796”号码。

尝试:

 $("#container").attr({ scrollTop: $("#container").attr("scrollHeight") }); 

从JQuery 1.9.1开始,您将需要:

 $("#container").scrollTop($("#container").prop("scrollHeight")); 

发布的答案不正确; scrollTop的最大值不是scrollHeight ,它是scrollHeight - outerHeight


这将为您提供正确的值:

 var elem = $("#container"); var maxScrollTop = elem[0].scrollHeight - elem.outerHeight(); 

没有jQuery的最佳方法。

 document.getElementById('container').scrollTop = document.getElementById('container').scrollHeight; 

使用jQuery它不适合我,所以如果有上面的问题,请尝试这个。