Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build floating menu bar when scroll down

Tags:

When I scrolled down site display black menu bar at the top look like float bar. but I think there's jquery involved with this. I have tried CSS but seems not working for me like the way i want it to

#menucontainer {     position:fixed;     top:0;     height: 250px }  #firstElement {     margin-top: 250px } 

Here is the website basic idea of what I would like the menu to be like:

http://avathemes.com/WP/Hexic/

like image 484
Mthe beseti Avatar asked Jun 18 '13 09:06

Mthe beseti


People also ask

What is floating navigation?

A floating navigation menu, sometimes called a sticky navigation menu, is a menu that stays visible on the page even as you scroll down. No matter where a visitor is on the page, they'll see your menu options either along the top or side of the page.


1 Answers

Wrap your menu in an div or section with an ID or class.

#yourID.fixed {     position: fixed;     top: 0;     left: 0;     z-index: 1;     width: 100%;     border-bottom: 5px solid #ffffff; }  //STICKY NAV $(document).ready(function () {     var top = $('#yourID').offset().top - parseFloat($('#yourID').css('marginTop').replace(/auto/, 100));   $(window).scroll(function (event) {     // what the y position of the scroll is     var y = $(this).scrollTop();      // whether that's below the form     if (y >= top) {       // if so, ad the fixed class       $('#yourID').addClass('fixed');     } else {       // otherwise remove it       $('#yourID').removeClass('fixed');     }   }); }); 

Can't remember where I got this from, so no salutations to me, but it worked for me.

like image 191
Kortschot Avatar answered Sep 22 '22 17:09

Kortschot