$("#content").scroll(function(e){
var distance_from_top = $("#content").scrollTop();
var theinverse = -1 * distance_from_top;
var theinverse2 = theinverse + "px";
$("#topheader").css( "marginTop", theinverse2);
});
执行上述操作最有效的方法是什么?基本上使 #topheader 上边距等于从顶部滚动的负距离。
最佳答案
缓存缓存缓存。
content = $("#content");
topheader = document.getElementById("topheader");
content.scroll(function() {
topheader.style.marginTop = -content.scrollTop() + "px";
});
关于javascript - 最有效的方法是什么(jquery 片段)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6065432/