Last active
November 15, 2017 06:02
-
-
Save Ben02/fb107bdc6f9be50d2c821a5d7963aef2 to your computer and use it in GitHub Desktop.
判断当前滚动高度并显示不同的东西(目录、二维码、评论框)。示例:https://munen.cc/tech/lazyload-Disqus.html
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
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) |
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
#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; | |
} |
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
$(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(); | |
} | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment