script and css to change nav background

This commit is contained in:
Thefeli73 2020-01-15 18:27:44 +01:00
parent 1da0437812
commit e690848eb4
2 changed files with 18 additions and 0 deletions

View File

@ -4,8 +4,16 @@
#nav {
@include vendor('transition', (
'height #{_duration(transition)} ease',
'background #{_duration(transition)} ease',
));
height: 80px;
position: fixed;
width: 100%;
background: #f2f2f2;
&.scrolled {
background: #ffffff;
}
> #wrapper {
margin: auto;

View File

@ -1,3 +1,4 @@
//toggle menu burger animation
document.getElementById("menuToggle").addEventListener("click", menuToggle);
function menuToggle() {
var bars = document.getElementsByClassName('bar');
@ -5,3 +6,12 @@ function menuToggle() {
bars[i].classList.toggle('active');
}
}
//toggle nav backgroundcolor
window.addEventListener('scroll', function() {
if (window.pageYOffset == 0) {
document.getElementById("nav").classList.remove('scrolled');
} else {
document.getElementById("nav").classList.add('scrolled');
}
});