2
I am trying to change the color of my header as soon as it passes 400px but when doing so my :Hover no longer works in the div after sliding down the bar
$(window).scroll(function() {
if ($(document).scrollTop() < 400) {
$('.color').css({
'background-color': 'black'
});
$('.sub-menu a').css({
'color': 'white',
});
} else {
$('.color').css({
'background-color': 'white'
});
$('.sub-menu a').css({
'color': 'black'
});
}
});
html,
body {
width: 100%;
height: 200%;
overflow-x: hidden;
}
header {
display: block;
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 1;
height: 60px;
}
.color {
background-color: black;
transition: 0.6s;
}
.sub-menu {
height: 60px;
text-align: center;
width: 100%;
margin: 0 auto;
float: left;
}
.sub-menu ul{
margin-top: 20px;
}
.sub-menu ul li {
display: inline-block;
list-style: none;
}
.aqui {
height: fit-content;
text-align: center;
background-color: red;
z-index: 0;
position: absolute;
top: 400px;
width: 100%;
}
.sub-menu a {
font-size: 17px;
text-transform: uppercase;
color: white;
padding-right: 30px;
text-decoration: none;
transition: 0.6s;
}
.sub-menu a:hover {
color: orangered;
transition: 0.5s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html lang="pt">
<head>
<title>Teste</title>
<meta charset="utf-8">
<link rel="stylesheet" href="./main.css">
</head>
<body>
<header class="color" >
<div class="logo-radical"></div>
<div class="sub-menu">
<ul>
<il>
<a >Home</a>
</il>
<il>
<a >Programacões</a>
</il>
<il>
<a >Times</a>
</il>
<il>
<a >Contato</a>
</il>
</ul>
</div>
</header>
<div class="aqui" id="aqui">
<span>Aqui !</span>
</div>
<script type="text/javascript" src="./main.js"></script>
</body>
</html>
Great, very well explained. Thank you
– Jordão Qualho
@Wingeds no problem young, glad you read the explanation, that makes a difference! []s
– hugocsl