0

I am using javascript and would like to have a menu in my website page when the page is scrolled to the top the menu background becomes transparent and when you scroll down the menu background changes and remains at the top of the page. I just can't find how you can know in javascript if your page is at the top. thanks

/

1 Answers1

0

This has been mostly answered here: How can I get the scrollbar position with JavaScript?

But I think this question has merit regardless. If you just wanted to do this in javascript, you can just use

document.body.scrollTop
// or 
document.getElementById("id").scrollTop

Given your use case though, there are some tricks you may be able to do without javascript at all. This gets covered in: Check scrolling with CSS

which I recommend reading about.

Hope that answers your question! Have a nice day!

IndevSmiles
  • 737
  • 6
  • 17