Skip to content

Instantly share code, notes, and snippets.

@Ben02
Last active November 15, 2017 06:02
Show Gist options
  • Save Ben02/fb107bdc6f9be50d2c821a5d7963aef2 to your computer and use it in GitHub Desktop.
Save Ben02/fb107bdc6f9be50d2c821a5d7963aef2 to your computer and use it in GitHub Desktop.
判断当前滚动高度并显示不同的东西(目录、二维码、评论框)。示例:https://munen.cc/tech/lazyload-Disqus.html
if theme.disqus
a#comments
#disqus_thread
script.
var disqus_run_count = 0;
var disqus_shortname = '#{theme.disqus}';
var disqus_identifier = '#{page.path}';
var disqus_title = "#{page.title}";
var disqus_url = '#{config.url}/#{page.path}';
var disqus = {
load : function disqus(){
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
disqus_run_count ++;
}
}
//script(id='dsq-count-scr' src='//#{theme.disqus}.disqus.com/count.js' async)
#toc {
font-size: 12px;
font-weight: 300;
line-height: 1.6;
display: none;
overflow: auto;
width: 100%;
max-width: 250px;
max-height: 250px;
margin: 60px auto 0;
padding: 10px 40px 0;
border-top: 1px solid #f2f2f2;
}
#toc ol {
list-style: none;
}
.toc-list {
padding-left: 10px;
}
#donate {
display: none;
width: 100%;
max-width: 450px;
margin: 60px auto 0;
}
.fadeInDown {
-webkit-animation-name: fadeInDown;
animation-name: fadeInDown;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
$(window).load(function() {
var target = document.getElementsByClassName('post')[0].scrollHeight;
var current = 0;
if (target < $(window).height()) {
$("#donate").css("display", "block");
disqus.load();
} else {
$(window).scroll(function() {
current = $(window).scrollTop();
if (current > target - $(window).height() && current < target) {
$("#toc").hide();
$("#donate").css("display", "block");
if (disqus_run_count == 0) {
disqus.load();
}
} else {
$("#donate").hide();
$("#toc").show();
}
})
}
})
if is_post()
if !page.hideToc
#toc.animated.fadeInDown
!= toc(page.content, {class: 'toc-list'})
if !page.hideDonate
img#donate.animated.fadeInDown(src="/images/donate.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment