I was wondering how to make a div tag float within the screen when a user scrolls down or up on a browser?
当用户在浏览器上向下或向上滚动时,我想知道如何在屏幕上浮动div标签?
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.
例如:yelp.com:http://yy.com.com/search?find_desc=&ns=1&find_loc=los+angeles%2Cca如果你看看他们在右侧的地图,它会固定在一个位置但是当你向下滚动,地图会随你滚动。
Can someone help me?
有人能帮我吗?
Thank you!
1 个解决方案
#1
5
var $sdiv = $("#mydiv");
$(window).scroll(function() {
$sdiv.stop().animate({
"marginTop": ($(window).scrollTop() + 50) + "px"
}, "slow");
});
Check working example at http://jsfiddle.net/N7xqC/
#1
5
var $sdiv = $("#mydiv");
$(window).scroll(function() {
$sdiv.stop().animate({
"marginTop": ($(window).scrollTop() + 50) + "px"
}, "slow");
});