Last active
July 31, 2016 17:25
-
-
Save fdcore/fe8b82066222efd3a23d29f076b7ed63 to your computer and use it in GitHub Desktop.
Load comments only if user viewed
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
// http://stackoverflow.com/a/488073 | |
function isScrolledIntoView(elem) | |
{ | |
var docViewTop = $(window).scrollTop(); | |
var docViewBottom = docViewTop + $(window).height(); | |
var elemTop = $(elem).offset().top; | |
var elemBottom = elemTop + $(elem).height(); | |
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop)); | |
} | |
var comments_loaded = false; | |
$( window ).scroll(function() { | |
if(isScrolledIntoView('#comments_form')){ | |
if(comments_loaded == false){ | |
// load_comments(); | |
comments_loaded = true; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment