JSFiddle - React, Tailwind, and code Playground

by Alexandru Gatea

CSS

body {
	height: 5000px;
}

JavaScript

function logScrolledPixels() {
  // Function to calculate the amount of scrolled pixels
  function getScrolledPixels() {
    return Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop);
  }

  // Event listener for the scroll event
  window.addEventListener('scroll', function() {
    var scrolledPixels = getScrolledPixels();
    console.log('Scrolled pixels:', scrolledPixels);
  });
}

// Call the function to start listening for the scroll event
logScrolledPixels();