Implementation Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var rollSet = $ ('# widget ');
Var offset = rollSet. offset ();
Var fwidth = $ ("# footer"). height ();
$ (Window). scroll (function (){
Var scrollTop = $ (window). scrollTop ();
Var scrollBtm = $ (document). height ()-$ (window). scrollTop ()-$ ("# widget"). height ();
If (offset. top <scrollTop ){
If (scrollBtm> fwidth ){
RollSet. removeClass ('absolute '). addClass ('fixed ')
} Else {
RollSet. removeClass ('fixed'). addClass ('absolute ')
}
} Else {
RollSet. removeClass ('fixed ')
}
})
</Script>
Method description:
The height of the page minus the scroll height and the height of the layer with ID as the widget is equal to the height from the bottom of the layer to the bottom;
When the distance from the bottom is less than or equal to the distance from the bottom of a specific position, remove the style fixed and add absolute positioning to the layer!
Add position: relative to the parent layer in CSS;