Active State For Navigation Bar In Website
Jul 26, 2009
I'm quite new to web design and Javascript in particular. How to resolve a problem with the navigation bar in a website I am currently working on. The navigation bar has 3 main categories and there is an 'active' state so the page currently viewed is shown as grey underline text in the navigation bar. The thing is, I also have sub-categories that are not included in the navigation bar but I'd like to make it so the sub-category page currently being viewed makes the main category to which it is attached showing as 'active' in the navigation bar.
This is the structure of my site:
index.html
contact.thml
illustration
index.html
illustrationproject1.html
illustrationproject2.html
illustrationproject3.html
photography
index.html
photography1.html
photography2.html
So for example, if I'm in illustrationproject1.html, the Illustration tab in the navigation bar should be on the active state. This is the code I have so far:
Navigation Bar:
[CODE]
<ul id="nav">
<li class="nav_item"><a href="illustration/index.html">Illustration</a></li>
<li class="nav_item"><a href="photography/index.html">Photography</a></li>
<li class="nav_item"><a href="design/index.html">Design</a></li>
<li class="nav_item"><a href="stories/index.html">Stories</a></li>
<li class="nav_item"><a href="profile.html" title="Profile">Profile</a></li>
<li class="nav_item"><a href="contact.html" title="Contact">Contact</a></li>
<li class="nav_item"><a href="links.html" title="Links">Links</a></li>
</ul>
[ICODE]
This is the Javscript for the active state:
[CODE]
function setActive() {
aObj = document.getElementById('nav').getElementsByTagName('a');
for(i=0;i<aObj.length;i++) {
if(document.location.href.indexOf(aObj[i].href)>=0) {
aObj[i].className='active';
}}}
[ICODE]
So this code is working but I'm just not sure how to apply it to the subcategories as well. I can see what I should do, write some "if" statement but I don't enough of Javascript yet for this...
View 2 Replies
ADVERTISEMENT
Apr 18, 2010
I am not terribly familiar with Javascript but i am looking forward to learning, and currently the problem I am facing is this:I have an a file being included to an .shtml document, that serves as my navigation, the code is like this:
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a class="MenuBarItemSubmenu" href="#">Home</a>
<ul>
[code]....
View 12 Replies
View Related
Feb 2, 2011
I am attempting to make a menu that has a background image that changeswhen you rollover or click a menuitem. I've got the hover effect working fine with CSS, but am trying to implement the click event via jquery with the following:
CSS:
div.SustainResourcesMenuTabs
{ background-image: url('/images/departments/commdev/sustainability/menu_tab.jpg');
}[code]....
My process is to reset the entire menu to the inactive state, then switch on the active state for the item that was clicked. Eventually, the item that was clicked will display its corresponding body section as well. I've tried using the CSS pseudo-class "active", but since the entire div is the link, that is unavailable. I've also tried multiple variations of addClass/removeClass, toggleClass, and setAttribute/removeAttributebut nothing hasworked so far.
View 2 Replies
View Related
Jun 28, 2009
i have a list of thumbnails that are created dynamically from a database which have an transparency state when the thumbnail is in the active state (ie when someone clicks on it)I wondered is there anyway that the first one could be set to active by default when the page initially loads. My code is below:
<script language="JavaScript" type="application/javascript">
<!--
function setMainImage(imageId) {
[code]....
I wonder how I can highlight the active thumbnail so its background remains blue until I click another one.I also like to avoid the inline JavaScript.
View 10 Replies
View Related
Jan 11, 2012
Having a navigation menu desighned in photoshop, how can I use jquery to add a active state class to my css which can use the same hover style for active menu?
Here is the HTML code:
<ul id="nav">
<li id="list1"><a href="#"><span>Home</span></a></li>
<li id="list2"><a href="#"><span>About Us</span></a></li>
<li id="list3"><a href="#"><span>Projects</span></a></li>
[Code]....
View 3 Replies
View Related
Nov 7, 2010
At the link below I've built the nav using CSS (see code below). How do I make the 'on' state stay active on each specific page? (i.e the 'about us' rollover image stays active on the 'about us' page)
[URL]
CSS:
/* -----------begin nav layout styles-------------- */
#navigation {
width: 455px;
height: 116px;
[Code].....
View 4 Replies
View Related
Dec 18, 2010
I am attempting to set it so that upon clicking a link within this Joomla site (from the navigation menu), the link will become bold. I have already implemented CSS for ".active" and set the "LI" class to 'active' to the first class.
I have done a search for the JQuery code to do this, but each example that I tried did not work at all. The class remained to be on the first link, home.
[Code]...
View 1 Replies
View Related
Oct 25, 2011
I'm building a WordPress site with a nice jQuery effect that fades/unfades images within a navigation menu on rollover. So when the mouse moves off the image, the colored image should fade back to reveal the original non-colored image. This works perfectly as-is, but client wants the active page to keep its colored/ highlighted menu image when mouse has moved off of it. The bolded line of the code is where I tried to set that up...
Code:
<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
<script type="text/javascript"><!-- this is from [URL]-->
// make nav images highlight on hover
// when the DOM is ready:
$(document).ready(function () {
// find the navigation elements and hook the hover event
$('#mainmenu li').hover(function() {
// on hovering over, find the element we want to fade *up*
var fade = $('> div', this);
// if the element is currently being animated (to a fadeOut)...
if (fade.is(':animated')) {
// ...take it's current opacity back up to 1
fade.stop().fadeTo(250, 1);
} else {
// fade in quickly
fade.fadeIn(250);
}}, function () {
// on hovering out, fade the element out
if (!is_page(current)){
var fade = $('> div', this);
if (fade.is(':animated')) {
fade.stop().fadeTo(3000, 0);
} else {
// fade away slowly
fade.fadeOut(2000);
}}});});
</script>
<ul id="mainmenu">
<li id="home">
<a href="/home"><img src="<?php bloginfo(url); ?>/wordpress/wp-content/uploads/2011/09/sara_inactive.png" alt="home" width="152" height="309" /></a>
<div>
<a href="/home"><img src="<?php bloginfo(url); ?>/wordpress/wp-content/uploads/2011/09/sara_active.png" alt="home" width="152" height="309" /></a>
</div>
</li>
WordPress should know whether the page is 'current' or not, so why doesn't this work? Currently the nav images remain highlighted when the mouse moves away. If I remove my attempt (the bolded line of code) then nav rollovers work beautifully, but active page still isn't represented with a colored nav menu image.
View 9 Replies
View Related
Aug 11, 2011
I am trying to develop a jquery based keyboard navigation for my new project.....
My code:
But the problem i face is that when my active link goes to first element of unordered list and then i press up arrow key, then i lose track of my active link...
View 3 Replies
View Related
Nov 15, 2010
I know that others have asked about adding a class to a navigation based on indow.location, but I couldn't quite fit my question within those bounds, so hopefully it's alright to ask here.RequirementAdd a class based on window locationComplexityThe current if/else method I have doesn't work correctly, because all subsequent URLs will have the initial word we're looking for,andI'd like to have the final else to be on nav id#3 - (because the url's there will all be varied and may change later so adding those specifically in the if/else seems redundant)So far I've probably explained nothing, so here's what the code looks like:
if (window.location.pathname.match(/(employees)/)) {
$('#nav1').addClass("selected");
}
[code]....
View 2 Replies
View Related
Jul 20, 2005
I am currently working on a static website for an auto parts company.
I've spent quite a long time with the owner of the business in
developing a javascript version of a windows explorer type of
navigation to be able to find these parts.
I was just notified that the individual that wants this done also does
not want the external .js file to be able to be copied, and someone
else profit from his/our work. I know that you cannot hide a client
side file; no matter how hard you try someone can get it. However, if
I deciped to go with a database instead, could I use a variant of this
file or convert it to another type that will allow me to use an access
dbase that we have, and yet keep my navigation the way I programmed
it?
View 1 Replies
View Related
Jul 19, 2011
i want to load the content in the #contentscroll-div.at the leftmenu navigation all works fine with buttons and stuffthe headpic works fine eitherbut i wanted to have some links in my inner content (which is in #contentscroll-div). i gave them the class .contentlink and added the class to my click function. but it doesn't work.
$(document).ready(function()
{
$("#contentscroll").load("sites/home.html").fadeIn("slow");
[code]....
View 1 Replies
View Related
Aug 22, 2010
Im trying to learn how to scroll using arrow keys or hotkeys. Where you're able to use your arrow keys to move side to side and up and down.
Here are the 2 best examples of how it functions:
thinkingforaliving[dot]org/archives/4580
ffffound[dot]com (top right says hotkeys to scroll with)
Can anyone link me to how to script that? Or even if there's a proper term I should know about to search for tutorials..
View 1 Replies
View Related
May 19, 2011
I'm trying to use the cookie plugin to remember the state of a navigation menu from page to page. Here is the snippet of code from towards the top of my page where I am including the jquery files and cookie plugin. The second part of the sample tries to determine whether the cookie exists.
[Code]....
View 1 Replies
View Related
Jun 8, 2011
getting all the header text:jQuery("#accordion h3").text();how do you get the active index? and how do you use that index to get the active header?how do you get the header text for the active header?
View 1 Replies
View Related
Nov 1, 2011
I used the code from the following article...[URL]
$(function() {
$('img[data-hover]').hover(function() {
$(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('data-hover')).attr('data-hover',
[code]...
why does the rolled over image's src return to the original value when the user rolls back off it?
View 1 Replies
View Related
Jul 21, 2011
To say I'm new to JavaScript is a bit of an understatement so bear with me. I have a site set up with a variety of layers of toggles. When you enter the site all of the items are collapsed and you click the headings to expand. Each of the toggle-able items have ids. It works great for users who start at the homepage.
However, when I send people to any of the inner topics, all they see is the initial collapsed state of the site. I want to be able to provide a URL that will set the toggle to open, and show all of the content for that section on entry.
Here is my code and js, can anyone point me in the right direction?
[Code]....
View 2 Replies
View Related
Jun 1, 2010
How can I preserve the session state of a SharePoint browser state using javascript?
View 2 Replies
View Related
Nov 2, 2009
I'm trying to implement a minimal navigation bar using jQuery's toggleClass() function but can't seem to get it working.
It's the .img_selector div at the bottom of the page:[url]
I want to toggle the 'active' class for each <a> when it's selected, to indicate which image is showing, so after calling jQuery, in the <head> I've got:
Then the links, which also include the showPic function:
View 4 Replies
View Related
Feb 6, 2011
I want to create an own horizontal navigation and so the navigation is a nested list like
<ul id="mymenu">
<li>entry1
<ul class="abc">
[code]....
View 3 Replies
View Related
Mar 6, 2009
I think this is just a dumb question, I'm missing some basic logic here about jquery "grammar".
I'm trying to do an image swap on hover that checks to be sure the thumbnail is not the active thumbnail. So mouseover, it swaps. Mouseout, swaps back, unless the thumb has been clicked.
Here's a snippet of the code that doesn't work:
How do I check that _li is not ".active" and replace the src if it isn't?
View 10 Replies
View Related
Aug 8, 2009
<div>
</div><div>I did some navigation menu and sub menu using jquery ,</div><div>
</div><div>like ;</div><div>
</div><div>Menu1 </div><div> Sub menu1(some.php)</div><div> Sub menu2(some1.php)</div><div>
[Code]..
View 1 Replies
View Related
Jan 28, 2010
The javascripts files in my website are constantly getting injected with malicious codes which redirects my website
View 2 Replies
View Related
Dec 29, 2005
I'm trying to code a feature for my website using DHTML where the person viewing the website can rotate between viewing the positive/negative points of the website being reviewed. This example was in the publication called Using HTML 4 by Lee Anne Phillips. Code:
View 5 Replies
View Related
Nov 30, 2010
I have a ajax program on a page on website A. And I need to let it talk to a program on website B. I tried to put website B into the url of the parameter but it doesn't work.It gives me a "[objet XMLHttpRequest]" error.here is the code on website A:
[Code]...
View 1 Replies
View Related
Jan 19, 2009
Ive been working on a site with a dropdown menu. its styled with css and animated with java i would like to add support for keyboard navigation.
var DDSPEED = 5;
var DDTIMER = 5;
main function to handle the mouse events [code].....
View 1 Replies
View Related