嗨,大家我想要做简单的滚动共享框小部件,但它不工作。它必须停止在特殊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) –