Sha256: bab2c95c7341a41ed5b84698d433a7a4b965c897de9b32ddeee0d23dcd0eca6d

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

<div id="up-button" class="fixed bottom-5 right-5 p-2 text-white rounded-full shadow-md cursor-pointer transition duration-300 ease-in-out bg-slate-100" style="display: none;">
    <a href="#top">
      <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-6 h-6" style="color: {{site.color}};">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
      </svg>
    </a>
  </div>
  <script>
    document.addEventListener('DOMContentLoaded', function() {
      var upButton = document.getElementById('up-button');

      // Function to handle scroll event
      function handleScroll() {
        if (window.scrollY > 100) {
          upButton.style.display = 'block'; // Show the button when scrolled down
        } else {
          upButton.style.display = 'none'; // Hide the button when at the top
        }
      }

      // Add scroll event listener
      window.addEventListener('scroll', handleScroll);

      // Initial check to show/hide the button based on initial scroll position
      handleScroll();

      // Add click event listener to scroll to the top when the button is clicked
      upButton.addEventListener('click', function(e) {
        e.preventDefault();
        window.scrollTo({
          top: 0,
          behavior: 'smooth'
        });
      });
    });
  </script>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wind-theme-0.1.3 _includes/up_button.html
wind-theme-0.1.2 _includes/up_button.html
wind-theme-0.1.1 _includes/up_button.html