JSFiddle - React, Tailwind, and code Playground
by Manju06
HTML
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled Document</title>
<link href="Web Site CSS.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="mySidenav" class="sidenav">
<a href="#" id="about">About</a>
<a href="#" id="blog">Exhibitions</a>
<a href="#" id="projects">Past Work</a>
<a href="#" id="contact">Social Info</a>
</div>
<div style="padding:15px 15px 2500px;font-size:30px;margin-top:30px; z-index:2;">
<p><b>Looking to hide the nav bar when scrolled down and if the page isn't at the top</b></p>
<p>Scroll down to understand what I'm meaning</p>
<p>Also looking to make it slide out when hovered over </p>
<p>Lorem ipsum dolor dummy text sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor dummy text sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</body>
</html>
CSS
body{
}
#mySidenav > a {
position:relative;
transition: 0.7s;
padding: 15px;
width: 100px;
text-decoration: none;
text-align: center;
font-size: 20px;
color: white;
border-radius: 5px 0 0px 5px;
opacity: .5;
border:1px solid black;
display:flex;
z-index:-1;
}
#mySidenav a:hover{
position:absolute;
display: inline-block;
border:1px solid red;
opacity: -1;
}
#about {
background-color: #4CAF50;
}
#blog {
background-color: #2196F3;
}
#projects {
background-color: #f44336;
}
#contact {
background-color: #555
}
JavaScript
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("about").style.right = "-10px";
document.getElementById("blog").style.right = "-10px";
document.getElementById("projects").style.right = "-10px";
document.getElementById("contact").style.right = "-10px";
} else {
document.getElementById("about").style.right = "-100px";
document.getElementById("blog").style.right = "-100px";
document.getElementById("projects").style.right = "-100px";
document.getElementById("contact").style.right = "-100px";
}
prevScrollpos = currentScrollPos;
}