- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the role of scrollY property in JavaScript?
The scrollY property in JavaScript works the same as pageYoffset property. If you want to get the pixels the document scrolled to from the upper left corner of the window, then use the scrollY property for vertical pixels.
Example
You can try to run the following code to learn how to work with scrollY property in JavaScript.
<!DOCTYPE html> <html> <head> <style> div { background-color: yellow; height: 1500px; width: 1500px; } </style> </head> <body> <script> function scrollFunc() { window.scrollBy(200, 200); alert("Vertical: " + window.scrollY); } </script> <button onclick="scrollFunc()" style="position:fixed;">Scroll</button> <br><br><br> <div> </div> </body> </html>
Advertisements
To Continue Learning Please Login
Login with Google