javascript moving text from left to right onscroll 1

javascript moving text from left to right onscroll

var text = document.querySelector("h1");
document.addEventListener("scroll", () => {
  text.style.left = window.scrollY * 5 + "px";
});

Here is what the above code is Doing:
1. We select the h1 element and store it in a variable called text.
2. We add an event listener to the document that listens for the scroll event.
3. When the scroll event is triggered, we set the left property of the text variable to the window.scrollY value multiplied by 5.

The window.scrollY property returns the number of pixels that the document is currently scrolled vertically.

So, when the user scrolls down, the left property of the h1 element will be set to a value that is 5 times the number of pixels that the document is scrolled.

This will cause the h1 element to move to the right as the user scrolls down.

Similar Posts