On the jQuery documentation pages, I notice that the Disqus comments do no open until I scroll to that part of the page.
Scroll down the bottom of this page and you’ll notice the affect: http://api.jquery.com/child-selector/
I was wonder how this was done as I would like to use it on my website as it will help reduce the page loading time.
Having a look at the source for that page, starting on line 461 or so:
They first get the offset for the top of the comments div:
then they define a function called
check()that checks to see what the current scroll height of the window is and if that, plus the window height, is greater than the offset value then they load the disqus script:Then they bind this
check()function to thescrollevent of the window:tl;dr: Everytime you scroll the page, they are checking the height of the scroll against the offset height of the comments div and if it’s viewable, then it loads the disqus scripts (which loads the comments).
HTH 🙂