I’m just not sure how to call a function when I scroll to a specific section on my page.
EXAMPLE:
I want to change the color of a text when I scroll to the article section.
or… I want to hide a button when I scroll on the last sections of the page.
or… I want to change the background of the page when I scroll to the footer.
I tried something like:
function func() {
var paragraph = document.getElementById('p');
paragraph.style.color = 'red';
};
<section>
<p id="p" onload="func()">
Test
</p>
</section>
2
Answers
You have to use intersection observer
https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver
This function return true if the element is visible and false if not.
this is a demo code you just have to change the variables to use it