我正在使用滚动事件,并且在滚动中的某些点上,我将后端称为新数据。我在获取scrollTop当前值进行更新时遇到问题。我想念什么?我需要拥有scrollTop
的新近更新的值,这样我才能不通过支票。似乎有些基本的东西,但我看不到...
这是代码示例:
var newspanel = $(".newspanel");
newspanel.on("scroll", function() {
var el = $(this);
var scrollTop = el.scrollTop();
var loading = false;
if (scrollTop <= 1000 && !loading) { // I don't want to get into this if statement when getData callback is called and processed
loading = true;
var url = "some_url";
getNewData(url, function(data) {
var newScrollTop = 300; // There is logic that calculates new scrollTop
el.scrollTop(newScrollTop); // Scroll is set further down, > 1000 in this example
loading = false;
})
}
});