I'm look to do the following http://codepen.io/anon/pen/eIfdn for the Twitter bootstrap navbar. It simply adds a shadow to the navbar upon scrolling. Any advice would be helpful thank you.
.navbar {
*position: relative;
top: 0;
left: 0;
width: 100%;
height: 80px;
z-index: 999;
-webkit-box-shadow: 0 8px 8px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 8px 8px rgba(0, 0, 0, 0.5);
box-shadow: 0 8px 8px rgba(0, 0, 0, 0.5);
display: none;
*z-index: 2;
margin-bottom: 20px;
overflow: visible;
}
Thats the css I changed and I added in the js from above.
Here's the JS I used
$(document).ready(function(){
$(window).scroll(function(){
var y = $(window).scrollTop();
if( y > 0 ){
$("#navbar").css({'display':'block', 'opacity':y/20});
} else {
$("#navbar").css({'display':'block', 'opacity':y/20});
}
});
})
Here is somenthing to get you started:
http://jsfiddle.net/panchroma/pyYfG/
HTML
<div class="navbar" data-spy="affix">
<div class="navbar-inner">
.... standard navbar stuff ...
</div>
</div>
<div id="top-shadow"></div>
.... page content ...
CSS
#top-shadow {
position: fixed;
top: 0;
left: 20px;
width: 100%;
height: 42px;
z-index: 999;
-webkit-box-shadow: 0 8px 8px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 8px 8px rgba(0, 0, 0, 0.5);
box-shadow: 0 8px 8px rgba(0, 0, 0, 0.5);
display: none;
}
.navbar.affix{ /* position fixed navbar */
top:0;
width:100%;
}
/* UPDATE BELOW */
.navbar{
z-index:1000; /* lift .navbar above #top-shadow */
}
The important bits are that I'm using the affix behaviour to lock the navbar inplace, and I'm applying the shadow to a new div just below the navbar. I think this will be easier to manage that trying to add a shadow directly to the navbar itself.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With