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 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> 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 %} {% include js-selector.html %}

View file

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

View file

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

View file

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