This is a simple plugin I've thrown together for my blog/personal site, where I use it to defer the loading of Disqus comments. This script can be used to defer the loading of third party plugins, scripts, or anything else you want to do once elements have come into view.
The plugin uses jQuery's Deferred Object API.
$.inView()
- The $.inView() function, when called will return a new jQuery.Deferred object that will resolve once all elements in the jQuery object have come into view.
$.when($('#myElement').inView()).then(function($el){
alert($el.attr('id') + ' is now in view');
});
Or
$('#myElement').inView(function(){
alert($(this).attr('id') + ' is now in view');
});