The following is the plug-in source code:
$. Fn. stickyfloat = function (options, lockBottom ){
Var $ obj = this;
Var parentPaddingTop = parseint(incluobj.parent().css ('padding-top '));
Var startOffset = $ obj. parent (). offset (). top;
Var opts = $. extend ({startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom: true}, options );
Export obj.css ({position: 'absolute '});
If (opts. lockBottom ){
Var bottomPos = $ obj. parent (). height ()-$ obj. height () + parentPaddingTop;
If (bottomPos <0)
BottomPos = 0;
}
$ (Window). scroll (function (){
$ Obj. stop ();
Var pastStartOffset = $ (document). scrollTop ()> opts. startOffset;
Var objFartherThanTopPos = $ obj. offset (). top> startOffset;
Var objBiggerThanWindow = $ obj. outerHeight () <$ (window). height ();
If (pastStartOffset | objFartherThanTopPos) & objBiggerThanWindow ){
Var newpos = ($ (document). scrollTop ()-startOffset + opts. offsetY );
If (newpos> bottomPos)
Newpos = bottomPos;
If ($ (document). scrollTop () <opts. startOffset)
Newpos = parentPaddingTop;
$ Obj. animate ({top: newpos}, opts. duration );
}
});
};
The method is simple: you just need to introduce the plug-in to the page and then call it with the selector:
?
$ ('# Menu15'). stickyfloat ({duration: 500 });
$ ('# Menu14'). stickyfloat ({duration: 500 });
$ ('# Menu13'). stickyfloat ({duration: 500 });
$ ('# Menu12'). stickyfloat ({duration: 500 });
The subsequent duration parameter indicates the sliding speed. The larger the sliding speed, the slower the sliding speed.
From jia58960