A jQuery plugin for 'locking' short content in place as the user scrolls by longer content. For example, it will lock metadata and share buttons in place as the user scrolls by a long essay or series of images.
This is used for the posts feed on Artsy, in this example and on this page.
Include required Javascripts
<script src="jquery.js"></script>
<script src="dist/poplockit.min.js"></script>
Create html like this
<div id="feed">
<article>
<div class="column">Left</div>
<div class="column">Center</div>
<div class="column">Right</div>
</article>
...
</div>
Apply the popLockIt plugin
$('#feed').popLockIt({
feedItems : $('#feed > article'),
columnSelector : '> .column'
});
jQuery object for you feed items.
Selector string to get the columns for your feed items relative to a feed item element. It is used in jQuery.popLockIt like so: $feedItem.find(columnSelector);
Pass in preventFixed: true to have popLockIt use position absolute instead of fixed. This is useful for supporting browsers (Safari on iOS) that do not support position fixed.
This function will be called every time the popLockIt scroll event fires. Useful for infinite scroll functionality. We recommend that you pass in a throttled function so that it does not affect scroll performance.
Function that runs after each feed item is initialized. Passes a jquery wrapped element and the index of that element in the feed.
returns feedItems and their columns to their default positions and unbinds all events.
Recomputes height / top / bottom etc of each feed item and its columns. Run if the size of any of your feed items has changed.
Recomputes height / top / bottom etc of one feed item and its columns. Run if the size of only one feed item has changed.
Recomputes height / top / bottom etc of one feed item's column. Run if one column of one of your feed items has changed.
Manually run the onScroll event. Recommend running this if you have hidden the feed and are now re-showing it.
Add items to the feed. Takes a jQuery object containing the new feed items.
Stop popLockit from running. Useful if you want to temporarily disable popLockit functionality.
Restarts popLockit after calling Stop
Contributions and pull requests are very welcome. Please follow these guidelines when submitting new code.
npm install -g grunt
for Grunt
brew install phantomjs
for PhantomJS
npm install
to install dependenciesgrunt
(compiles coffeescripts and runs tests)grunt watch
while editing files to auto-compile coffeescripts and run testsgrunt jasmine
to see if tests fail.grunt
to compile new dist and make sure nothing is broken