Improve JS loading sequence

This commit is contained in:
Cotes Chung 2020-12-10 19:49:43 +08:00
parent d53769e52b
commit cdaa79cf80
4 changed files with 34 additions and 30 deletions

View file

@ -61,7 +61,7 @@
<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
<script async
<script defer
src="https://cdn.jsdelivr.net/combine/npm/popper.js@1.15.0,npm/bootstrap@4/dist/js/bootstrap.min.js"></script>
{% include js-selector.html %}

View file

@ -18,8 +18,8 @@
{% if page.math %}
<!-- MathJax -->
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script defer src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script defer src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
{% endif %}
{% if jekyll.environment == 'production' %}

View file

@ -3,7 +3,7 @@
-->
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>
$(function() {
let initTheme = "default";
if ($("html[mode=dark]").length > 0
@ -16,6 +16,7 @@
theme: initTheme /* <default|dark|forest|neutral> */
};
/* Markdown converts to HTML */
$("pre").has("code.language-mermaid").each(function() {
let svgCode = $(this).children().html();
@ -24,5 +25,5 @@
});
mermaid.initialize(mermaidConf);
});
</script>

View file

@ -1,18 +1,21 @@
/*
Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
*/
$(window).scroll(function() {
if ($(this).scrollTop() > 50
&& $("#sidebar-trigger").css("display") === "none") {
$(function() {
$(window).scroll(function() {
if ($(this).scrollTop() > 50 &&
$("#sidebar-trigger").css("display") === "none") {
$("#back-to-top").fadeIn();
} else {
$("#back-to-top").fadeOut();
}
});
});
$(function() {
$("#back-to-top").click(function() {
$("body,html").animate({scrollTop: 0}, 800);
$("body,html").animate({
scrollTop: 0
}, 800);
return false;
});
});