Add this line to your application's Gemfile:
gem 'onScreen-rails'
And then execute:
$ bundle install
Add to your app/assets/javascripts/application.js
//= require jquery.onscreen
Or for the minified version
//= require jquery.onscreen.min
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
});
Usage documentation as well as demos can be found at: