Created
November 15, 2013 12:29
-
-
Save mailopl/7483597 to your computer and use it in GitHub Desktop.
Loads Disqus when scrolled down to disqus div.
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
/* | |
|--------------------------------------------------------------------------------------- | |
| 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