开发者

div tag float in view when browser scrolls

I was wondering how to make a div tag开发者_运维问答 float within the screen when a user scrolls down or up on a browser?

For example: yelp.com : http://www.yelp.com/search?find_desc=&ns=1&find_loc=los+angeles%2Cca If you look at their map on the right side, it is fixed in a position but when you scroll down, the map will scroll with you.

Can someone help me?

Thank you!


var $sdiv = $("#mydiv");
$(window).scroll(function() {
    $sdiv.stop().animate({
        "marginTop": ($(window).scrollTop() + 50) + "px"
    }, "slow");
});

Check working example at http://jsfiddle.net/N7xqC/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜