I have for example a div
at a certain point on the page what I want is that when the scroll is in the same position as that div
I execute a function, for example:
if(Scroll == div){div.innerHTML="altura es ???'" ;}
I tried to do with scrollTop but I only run the function when the scroll is on the top and well I want to run it when both are over there, I do not know if I understand , here is my code
I would appreciate any help friends.
//asi es como lo se hacer pero no se si este correcto con srollTop
onscroll=function(){
var yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
var div = document.getElementById('pp');
if(yScroll == div.scrollTop){div.innerHTML="altura es: "+yScroll;}
}
div{
background:grey;
font-size:30px;
padding:5px;
font-weight:bold;
width:200px;
border-radius:5px;
}
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--cando el scroll lleque a este div quiero ejecutar una funcion-->
<div id="pp">0</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</body>
</html>