Welcome to mirror list, hosted at ThFree Co, Russian Federation.

main.js « js « assets - github.com/wayjam/hugo-theme-mixedpaper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5300c36f3b523dea03537333206051542a1782dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(function () {
  const backToTopBtn = document.getElementById("back_to_top");

  window.onscroll = function () {
    scrollFunction(backToTopBtn);
  };

  backToTopBtn.addEventListener("click", backToTop);
})();

function scrollFunction(btn) {
  const pageOffset =
    document.documentElement.scrollTop || document.body.scrollTop;
  if (btn) btn.style.visibility = pageOffset > 450 ? "visible" : "hidden";
}

// When the user clicks on the button, scroll to the top of the document
function backToTop(e) {
  e.preventDefault();
  document.body.scrollTop = 0; // For Safari
  document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}