What is the most efficient way to do this (jquery snippet)?
$("#content").scroll(function(e){
var distance_from_top = $("#content").scrollTop();
var theinverse = -1 * distance_from_top;
var theinverse2 = theinverse + "px";
$("#topheader").css( "marginTop", theinverse2);
});
What's the most efficient way to do the above? Basically make #topheader top margin equal to the negati开发者_如何学JAVAve distance scrolled from the top.
caching caching caching.
content = $("#content");
topheader = document.getElementById("topheader");
content.scroll(function() {
topheader.style.marginTop = -content.scrollTop() + "px";
});
Efficient or short because you could simply do this for shortness.
$("#content").scroll(function(e){
$("#topheader").css( "marginTop", -$("#content").scrollTop() + "px");
});
When probably need more context (source of the web page) if you want efficiency.
精彩评论