Home › Forums › JavaScript › nav bar changing position?
- This topic is empty.
-
AuthorPosts
-
November 15, 2014 at 9:13 pm #188399DoodayerParticipant
so in a basic rundown of what i want to happen, the nav bar should always be fixed at the top of the screen, which i’ve effectively done. but when i’m at the top of the home webpage, i would like for my logo to go above my nav bar and for the nav bar to stay securely below it. once i scroll down, the nav bar can move back up to its position and the top of its screen and stay there. I honestly have no clue how to do this, and wouldn’t begin to know how to summarize that in three key words for a google search.
http://codepen.io/Doodayer/pen/KwKxqgif theres a more efficient way of using the image as a link, feel free to inform me. I’m fairly new to this, as in maybe 3 hours of total writing experience. thanks for all the help.
November 15, 2014 at 11:08 pm #188400deeve007ParticipantUse Jquery.
Default has navbar positioned relatively so it sits below the logo.
Then when y position of nav bar reaches “0” use Jquery to change its position to “fixed” at the top of the screen.
Then when bottom y position of the logo is >0, revert the position of the navbar back to default.November 16, 2014 at 8:39 am #188430DoodayerParticipantOk i don’t have much experience with jquery, so heres what i have so far:
/*jquery navbar*/ var x = $(".nav").position().top; if (x = 0) { $(".nav").css("position", "fixed"); }else{ $(".nav").css("position", "relative"); };
I’m not sure if those are the methods i should use, or how to properly find the y position of the nav bar, but thats what i’ve got.
also a weird bug i’m getting is the nav bar doesn’t have the full width, even though its set to 100%.
November 16, 2014 at 1:19 pm #188439Paulie_DMemberSomething like this:
November 16, 2014 at 1:42 pm #188440deeve007ParticipantNot quite. Elements need to start off with position:relative, and then switch to position: fixed, and then vice versa when scrolling back.
November 16, 2014 at 1:43 pm #188441deeve007Participanthttp://codepen.io/anon/pen/qEBQMj
(click on the “edit” link to view it non-embedded)
November 16, 2014 at 1:54 pm #188442Paulie_DMemberNot sure
position:relative
is necessary…the ‘staticswitching to
fixed` is equally valid BUT it does look better.:)
November 16, 2014 at 1:55 pm #188443deeve007ParticipantBut it’s what he wants. The nav needs to move up with the logo/content, and THEN become fixed at the top of the screen.
Why would you want the nav to be “stuck” part way down the screen?? (until the logo disappears)
November 16, 2014 at 2:01 pm #188444Paulie_DMemberIt’s fixed below the header / logo and sticks to the top when the page is scrolled..which he wanted.
Yours is better though…as always, there’s many ways of doing something.
November 16, 2014 at 2:06 pm #188446deeve007ParticipantWell we’ve certainly interpreted what he was after in different ways, but I’m sure he can make his choice with the info we’ve given him now.
November 16, 2014 at 7:03 pm #188464DoodayerParticipantthank you both for all the help. it definitely helped me get a better understanding of what i needed to do.
November 16, 2014 at 8:29 pm #188467DoodayerParticipantI’m having another issue. for some reason the code all works in the codepen, but when i run it in firefox, it doesn’t work. Possible reasons?
November 16, 2014 at 8:30 pm #188468DoodayerParticipantdoesn’t work in chrome either.
November 16, 2014 at 8:35 pm #188469deeve007ParticipantHave you included the required library(ies)? (eg: jquery)
November 16, 2014 at 8:42 pm #188470DoodayerParticipantthats what i’m having issues with. when i try to download jquery it takes me into a webpage full of open javascript. should it do this? also if i copy all of that can i just access it like this?
<script type=”text/javascript” src=”jquery.js”></script>
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.