Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
722 B
1
Indexable
Never
<button id="buttontop" onclick="scrollToTop()">
      <img
        src="https://www.svgrepo.com/show/93813/up-arrow.svg"
        alt="Scroll to top"
        width="25"
        height="25"
      />
    </button>
    
    <script>
      window.onscroll = function () {
        var button = document.getElementById("buttontop");

        if (
          document.body.scrollTop > 50 ||
          document.documentElement.scrollTop > 50
        ) {
          button.style.opacity = "1";
        } else {
          button.style.opacity = "0";
        }
      };
      function scrollToTop() {
        window.scrollTo({
          top: 0,
          behavior: "smooth",
        });
      }
    </script>