Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  61] [ 6]  / answers: 1 / hits: 24693  / 12 Years ago, tue, april 10, 2012, 12:00:00

I want to create a navigation bar similar to this site's:



http://www.mysupermarket.co.uk/#/shelves/top_offers_in_asda.html



Can anyone tell me how to create that navigation bar, which follows you as you scroll the page down, but not following you at the initial loading of page?



When you access to the given website, try to scrolling down and you will understand what I am talking about. The navigation bar that consists of MY SHOP, OFFERS, IDEAS & LIFESTYLE, BAKERY and so-on...



I have really no idea what it's called. At least tell me what it's called, so I'll be able to search.



Here is the solution I've done



window.onscroll = function(){
if(getScrollTop()>140) {
document.getElementById(menu).style.position=fixed;
} else {
document.getElementById(menu).style.position=;
}
}

function getScrollTop() {
if (window.onscroll) {
// Most browsers
return window.pageYOffset;
}

var d = document.documentElement;
if (d.clientHeight) {
// IE in standards mode
return d.scrollTop;
}

// IE in quirks mode
return document.body.scrollTop;
}

More From » html

 Answers
75

Holding an element on same position can be achieved by fixed position styling.
If you want your navigation bar to stay on exact same location, position:fixed; is enough. (At least non IE6)



You can find a working example and some details here



However, if you want your navigation bar to move from it's initial location to the top border of page as you scroll the page down, you must implement some JavaScript to catch page scroll event and move the <div> accordingly.



See this question for an example on how to do that.


[#86336] Monday, April 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reed

Total Points: 725
Total Questions: 85
Total Answers: 89

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;