Skip to content

Instantly share code, notes, and snippets.

@mailopl
Created November 15, 2013 12:29
Show Gist options
  • Save mailopl/7483597 to your computer and use it in GitHub Desktop.
Save mailopl/7483597 to your computer and use it in GitHub Desktop.
Loads Disqus when scrolled down to disqus div.
/*
|---------------------------------------------------------------------------------------
| This function disqus when you scroll down to disqus div.
|
| @author Marcin Wawrzyniak
|---------------------------------------------------------------------------------------
*/
(function($){
var loadDisqus = function() {
var $window = $(window),
disqusPosition = $("#disqus_thread").offset().top;
if ($window.scrollTop() + $window.height() > disqusPosition) {
// Remember to setup the disqus_identifier somewhere
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + window.disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
return $window.unbind("scroll", loadDisqus);
}
};
$window.on("scroll", loadDisqus);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment