Rumah >hujung hadapan web >tutorial js >随窗体滑动的小插件sticky源码_javascript技巧
var pastStartOffset = $(document).scrollTop() > opts.startOffset;
var objFartherThanTopPos = $obj.offset().top > startOffset;
var objBiggerThanWindow = $obj.outerHeight()
if( (pastStartOffset || objFartherThanTopPos) && objBiggerThanWindow ){
var newpos = ($(document).scrollTop() -startOffset + opts.offsetY );
if ( newpos > bottomPos )
newpos = bottomPos;
if ( $(document).scrollTop() newpos = parentPaddingTop;
$obj.animate({ top: newpos }, opts.duration );
}
});
};