我注意到当ajax在页面顶部推送一些内容时会自动触发jquery滚动事件.任何专家都知道如何在添加内容时避免触发滚动事件?但是当用户运行鼠标滚轮,向上翻页以及键盘上下可能触发滚动事件?
$(window).on('scroll', function () {
console.log("User manual scrolled.");
});
Run Code Online (Sandbox Code Playgroud)
基于这个例子. https://jsfiddle.net/q00jnv4n/
阻止显示移动的一种方法是调整div 高度变化的scrollTop量,例如:#resultscrollTop = (scrollTop + newHeight - oldHeight)
function AddContent() {
var height = $('#result').height();
console.log("height: " + height);
$(".UnloadedPara").each(function () {
//console.log();
$(this).replaceWith("<div>This is some new paragraph</div>");
});
var newHeight = $('#result').height();
$(window).scrollTop($(window).scrollTop() + newHeight - height);
}
Run Code Online (Sandbox Code Playgroud)
JSFiddle: https://jsfiddle.net/TrueBlueAussie/q00jnv4n/12/
| 归档时间: |
|
| 查看次数: |
1858 次 |
| 最近记录: |