开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜