javascript - CSS and active state nav elements -
making active nav element menu isn't difficult, here example. http://jsfiddle.net/6neb6/38/
<ul> <li><a href="" title="home">home</a></li> <li class="active"><a href="" title="deals">deals</a></li> <li><a href="" title="support">support</a></li> <li><a href="" title="contact">contact</a></li> </ul>
css:
html { filter: expression(document.execcommand("backgroundimagecache", false, true)); } ul { background: url(http://shared.web2works.co.uk/tmp/tab-bg-top.png) no-repeat; height: 51px; font-family: arial; font-size: 14px; } ul li { float: left; height: 51px; } ul li { display:block; background: url(http://shared.web2works.co.uk/tmp/nav-seperator.gif) no-repeat top right; padding: 17px 20px 17px 21px; text-decoration: none; color: #263e60; } ul li:last-child a{ /*background-image: none;*/ } ul li:first-child a{ padding-right: 75px; } li.active a, li:hover { background: #02284c; color: #fff; margin-left: -2px; padding-left: 23px; }
what need bit different. in active states people tend style menu buttons can use same style every button. need buttons activate different image every state.
this image of i'm talking about:
those buttons have different glow effects different images. when select different button glow should stay active. if way i'm not able use same style every button.
the buttons change pages , hovers work correctly, i'm having trouble setting states each button active when reaches it's destination page. state works first button, home page.
here code(important bits):
<div id="wrapper"> </div> <div class="menu" id="menunav"> <ul class="menuul"> <li><a id="home-link">home</a> </li> <li><a id="work-link">work</a> </li> <li><a id="about-link">about</a> </li> <li><a id="contact-link">contact</a> </li> <li><a id="resources-link">resources</a> </li> </ul> </div>
css:
.menu { height: 50px; margin: auto; width: 650px; text-align:center; padding:10px; } .menu ul li { display: inline-block; margin: 0 10px; } .menu ul li { display: block; text-indent: -99999px; cursor: pointer; color: #00000; } #home-link { background: transparent url() no-repeat; width: 90px; } #home-link:hover, #home-link.current-item { background:url() no-repeat; } #work-link { background: transparent url() no-repeat ; width: 90px; } #work-link:hover, #about-link.current-item { background:url() no-repeat; } #about-link { background:url() no-repeat; width: 90px; } #about-link:hover, #services-link.current-item { background:url() no-repeat; } #contact-link { background: transparent url() no-repeat; width: 90px; } #contact-link:hover, #work-link.current-item { background:url() no-repeat; } #resources-link { background:url() no-repeat; width: 100px; } #resources-link:hover, #contact-link.current-item { background:url() no-repeat; } .current-item { }
js:
function switchscrollscroll() { var scrolloffset = $("#wrapper").scrollleft(); if(scrolloffset == 0 && scrolloffset <= 1999) { $('#menu ul li a').removeclass('current-item'); $('#home-link').addclass("current-item"); } else if(scrolloffset >= 2000 && scrolloffset <= 3999) { $('#menu ul li a').removeclass('current-item'); $('#work-link').addclass("current-item"); } else if(scrolloffset >= 4000 && scrolloffset <= 5999) { $('#menu ul li a').removeclass('current-item'); $('#about-link').addclass("current-item"); } else if(scrolloffset >= 6000 && scrolloffset <= 7999) { $('#menu ul li a').removeclass('current-item'); $('#contact-link').addclass("current-item"); } else if(scrolloffset >= 8000 && scrolloffset <= 10000)// contact { $('#menu ul li a').removeclass('current-item'); $('#resources-link').addclass("current-item"); } } switchscroll(); $("#wrapper").scroll(function(){ switchscrollcroll(); }); });
images taken out on purpose. if has done before, i'd appreciate help.
you can adding class body. example if have class work
on body of work page css can like
.work #work-link { background: transparent url(different image) no-repeat ; } #work-link { background: transparent url(default image) no-repeat ; width: 90px; }
if don't want go around editing every page can use jquery figure out page on , add appropriate class
Comments
Post a Comment