jQuery(document).ready(function() { var commentsLoaded = false; jQuery(window).scroll(function() { // Load comments when the Comments DIV is 600px below the bottom of the viewport var hT = jQuery('#comments').offset().top - 600, hH = jQuery('#comments').outerHeight(), wH = jQuery(window).height(), wS = jQuery(this).scrollTop(); if (wS > (hT + hH - wH) && commentsLoaded == false){ (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=475672159303398"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); commentsLoaded = true; } }); });