0
all right?
I would like to know how to capture the scroll of the page and appear the amount of scroll rolled on the console.
0
all right?
I would like to know how to capture the scroll of the page and appear the amount of scroll rolled on the console.
0
The javascript
has the object window
who owns the property scrollY
where it shows how much of scroll was made in the page...
try to use console.log(window.scrollY)
div{
height: 2000px;
}
<div>
<div>
<script type="text/javascript">
window.onscroll = scroll;
function scroll () {
console.log(window.scrollY , 'aa')
}
</script>
0
Oops! If you want to render the screen value on the page, you can create a function activated by the scroll event... and insert the screen value into the HTML of an element of your page. For example:
<body>
<div>
<h1>Valor do Scroll da pagina</h1>
<p id="valorScroll">x</p>
</div>
</body>
Apply this style so you can see the effect:
body{
height:200vh;
}
div{
position:fixed;
}
Ai you make a function:
window.addEventListener('scroll', function() {
document.getElementById("valorScroll").innerHTML=window.window.scrollY
}
Result pen: https://codepen.io/anon/pen/XQKjwr
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Good afternoon Otávio blz, the code you gave me really appears the value on the console but I wanted from the moment I scroll the console appear the amount in numbers, thanks.
– youtuber 23
Hi edited the answer see if it helps you...
– OtavioCapel