I have a plugin that does the opposite - it is in the stream of a web page, and when the user scrolls it, it is fixed in the viewport. However, it actually applies the css class to the element, so you can use it as is.
You can find the plugin here: https://github.com/hanssonlarsson/jquery-fixedscroll
Then I would suggest you create your element in the stream of your web page:
<div id="sometimesFixed">content</div>
Using css:
#sometimesFixed { position: fixed; bottom: 0; } #sometimesFixed.scroll { position: static; }
And apply the plugin like this in your JavaScript:
$('#sometimesFixed').fixedscroll({className: 'scroll'});
There is also a more general plugin, a very new one called jquery-waypoints. The idea is to associate any code with waypoints, points on a web page where some code is executed when the user scrolls past them.
https://github.com/imakewebthings/jquery-waypoints
It is probably more optimized and better suited than my plugin, but YMMV!
Linus Gustav Larsson Thiel
source share