Created
July 19, 2016 10:49
-
-
Save jimi008/5208cf9956beaf0416f04d84ced41dda to your computer and use it in GitHub Desktop.
Lazy Load The Facebook Comments Plugin Using JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function loadAPI() { | |
var js = document.createElement('script'); | |
js.src = '//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=YOUR_APP_ID&version=v2.0'; | |
document.body.appendChild(js); | |
} | |
window.onscroll = function () { | |
var rect = document.getElementById('comments').getBoundingClientRect(); | |
if (rect.top < window.innerHeight) { | |
loadAPI(); | |
window.onscroll = null; | |
} | |
} | |
</script> | |
<div id="fb-root"></div> | |
<div id="comments" class="fb-comments" data-href="YOUR_WEBPAGE" data-numposts="5" data-colorscheme="light"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment