onScreen Rails Gem
Installation
Add this line to your application's Gemfile:
gem 'onScreen-rails'And then execute:
$ bundle install
Usage
Add to your app/assets/javascripts/application.js
//= require jquery.onscreen
Or for the minified version
//= require jquery.onscreen.min
Example
Include jQuery and the plugin on a page.
$('elements').onScreen({
container: window,
direction: 'vertical',
doIn: function() {
// Do something to the matched elements as they come in
},
doOut: function() {
// Do something to the matched elements as they get off scren
},
tolerance: 0,
throttle: 50,
toggleClass: 'onScreen',
lazyAttr: null,
lazyPlaceholder: 'someImage.jpg',
debug: false
});Documentation
Usage documentation as well as demos can be found at: