<div id="stickyBar"> <ul> <li><a href="#">Link1 </a></li> <li><a href="#">Link 2 </a></li> <li><a href="#">Link 3 </a></li> <li><a href="#">Link 4 </a></li> <li><a href="#">Link 5 </a></li> </ul> </div>
#stickyBar { background: rgba(0,0,0, 0.8); border-radius: 0 0 0.5em 0.5em; display:none; height:40px; } #stickyBar ul { margin:0px; padding: 0; list-style:none; } #stickyBar ul li { float:left; min-width:80px; text-align:center; border-right:1px solid #ccc; font-size: 16px; height: 40px; line-height: 2.5em; padding:0 5px; } #stickyBar ul li a { color:#fff; display: block; width:100%; height:100%; } #stickyBar ul li a:hover { background: red; color:#fff; } #stickyBar.stick { position: fixed; top: 0; z-index: 10000; width:1000px; margin:0 auto; background: rgba(0,0,0, 0.8); border-radius: 0 0 0.5em 0.5em; display: block; }
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script> function sticky_relocate() { var window_top = $(window).scrollTop(); var div_top = $('.above_body').offset().top; if (window_top > div_top) { $('#stickyBar').addClass('stick'); } else { $('#stickyBar').removeClass('stick'); } } $(function() { $(window).scroll(sticky_relocate); sticky_relocate(); }); </script>
Show Your Support