嗨,大家我想要做簡單的滾動共享框小部件,但它不工作。它必須停止在特殊div(停止滾動)上,但它不停止並向下滾動,直到網頁頁腳。任何想法爲什麼?Javascript的滾動並沒有停止
var windw = this;
$.fn.followTo = function (elem) {
var $this = this,
$window = $(windw),
$bumper = $(elem),
bumperPos = $bumper.offset().top,
thisHeight = $this.outerHeight(),
setPosition = function(){
if ($window.scrollTop() <= (bumperPos - thisHeight)) {
$this.css({
position: 'absolute',
top: (bumperPos - thisHeight)
});
} else {
$this.css({
position: 'fixed',
top: 0
});
}
};
$window.resize(function()
{
bumperPos = pos.offset().top;
thisHeight = $this.outerHeight();
setPosition();
});
$window.scroll(setPosition);
setPosition();
};
$('#share_box').followTo('#stopscroll');
但它不停止在div #stopscroll上。
css文件看起來像這樣:
#share_box{
background: none repeat scroll 0% 0% #E1E1E1;
position: fixed;
width: 65px;
padding: 15px;
border-radius: 5px 0px 0px 5px;
left: 1.89%;}
什麼想法? 這裏的jsfiddle http://jsfiddle.net/NCY6x/
您是否添加jQuery? (這不是在你的jsfiddle) –