#Scroll Culling A jQuery Plugin
##Description
Author: Adam Magaña <[email protected]>
Last Edit: August 23, 2012
Version: 0.0.1
Based on the concept of back-face culling. Provides the ability to monitor a content area's scrollTop
property and invoke a callback function for rendering new content when the scroll position is at or near the fold. This prevents content from being rendered that is not in the viewable scroll area.
##Usage
<div id="scrolling_div">
<!-- Visible content is rendered here by the reveal callback method -->
</div>
<script>
$(document).ready(function () {
$('#scrolling_div').cull({
buffer: 0,
chunks: 10,
reveal: function (index) {
return '<p>' + index + ': Rendered by the reveal callback method!';
}
});
});
</script>
This usage is very simple and doesn't get much more complicated. Culling is instantiated on the #scrolling_div
element which means a few things automatically happen: the height of #scrolling_div
is calculated, the reveal function is called until the total content height of the inner HTML meets or exceeds the height of the div itself, and a scroll event listener is bound to determine when more content should be rendered for viewing. That's quite a mouthful but it's actually pretty simple.
Still confused? Check out the live demo here.
##Options
Not sure what the settings and options are? Not sure what they mean? This should clear things up:
Name | Type | Parameters | Default Value | Description |
buffer | integer | None | 0 | Number of pixels above the bottom of the scroll area to invoke the reveal callback method. |
chunks | integer | None | 5 | Number of times to invoke the reveal callback method when the scroll postion reaches the buffer. |
reveal | function (returns a string) | index | $.noop | Callback function that is invoked to render new content. |
##License
(The MIT License)
Copyright (c) 2012 Adam Magaña <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.