-2
I have the following page:
<style>
navbar {
color: #FFF;
position: fixed;
top: 0;
width: 100%;
height: 60px;
background-color: #000;
}
section {
width: 100%;
height: 100vh;
}
#sec-1 {
background-color: red;
}
#sec-2 {
background-color: blue;
}
#sec-3 {
background-color: green;
}
</style>
<navbar>
<a href="">Link 1</a>
<a href="">Link 2</a>
<a href="">Link 3</a>
</navbar>
<section id="sec-1"></section>
<section id="sec-2"></section>
<section id="sec-3"></section>
Depending on which section the scroll page is in, I would like to change the color of the navigation bar, as I could do this simply with Javascript?
Could provide us a [mcve] demonstrating what is trying to do.
– Augusto Vasques
Test your browser console for the command
this.scrollY
– Brenno Segolim
@Augustovasques I put.
– Mateus Daniel
@Brennosegolim but this should reference which element?
– Mateus Daniel
Reference to the element
window
, so much so that if you typewindow.scrollY
would be the same thing. Even better to usewindow.scrollY
, because if you usethis
within the context of a class, which will be referred to.– Brenno Segolim