I recently delved into the world of coding and I am just putting the finishing touches on my basic portfolio site.
The one issue that has been bothering me is the hamburger menu background. While I have successfully applied a background color to the menu using CSS, there seems to be a slight delay in the color change when clicking on it. It's a small detail, but it's been causing some frustration!
I apologize if my code is a bit messy. Any feedback or constructive criticism would be greatly appreciated!
Link: https://codepen.io/MikeyT24/pen/xrQvxe
HTML
<nav class="navbar fixed-top navbar-inverse navbar-toggleable-sm opaque-navbar">
<div class="container containernav">
<button class="navbar-toggler " type="button" data-toggle="collapse" data-target="#myContent" aria-controls="myContent" aria-expanded="false" aria-label="toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<h1 class="navbar-brand m-0 ">Michael Treeves</h1>
<div class="collapse navbar-collapse" id="myContent">
<div class="navbar-nav ml-auto">
<a class="nav-item nav-link" href="#about">About</a>
<a class="nav-item nav-link" href="#portfolio">Portfolio</a>
<a class="nav-item nav-link" href="#contact">Contact</a>
</div> <!--navbar-nav-->
</div> <!--collapse-->
</div> <!--container-->
</nav>
CSS
/***********************************************************
OPAQUE NAVBAR SECTION
**********************************************************/
.opaque-navbar {
background-color: rgba(0,0,0,0);
height: 50px;
border-bottom: 0px;
transition: background-color 0.5s ease 0s;
}
.opaque-navbar.opaque {
background-color: rgba(100,100,150,0.9);
height: 50px;
transition: background-color 0.5s ease 0s;
}
@media (max-width: 992px) {
.opaque-navbar {
height: 50px;
transition: background-color .5s ease 0s;
}
@media (max-width: 768px){
.collapse {
background-color: rgba(100,100,150,0.9);
}
Script (not sure if relevant)
* OPAQUE NAVBAR SCRIPT
**********************************************************
*/
// Toggle tranparent navbar when the user scrolls the page
$(window).scroll(function() {
if($(this).scrollTop() > 650) /*height in pixels when the navbar becomes non opaque*/
{
$('.opaque-navbar').addClass('opaque');
} else {
$('.opaque-navbar').removeClass('opaque');
}
});
Thank you for your help and feedback!
Sincerely, Mikey