javascript - Dynamic Navigation bar (with images) with jquery and php - problems with mouseover effects -
i'm building dynamic navigation bar controlled php, , i'm using images within list. , i'm applying jquery 'hover' effects. php code:
$path = $_server['php_self']; $page = basename($path); $page = basename($path, '.php'); and in navigation list i'm setting 'display:none' , 'display:inline' depending on return value of $page using php 'if' statement. see code:
<ul id="cssdropdown"> <li class="headlink"> <a class="lightnav" href="index.php" <?php if($page == 'index'){echo "style='display:none !important'";}else{echo "style='display:inline'";}?>><img src="images/navbuttons/home.png" /></a> <a class="darknav" href="index.php" <?php if($page == 'index'){echo "style='display:inline !important'";}else{echo "style='display:none'";}?>><img src="images/navbuttons/home-dark.png" /></a> </li>.... this working fine, display of nav bar images change depending on page user at. problem i'm trying integrate jquery nice 'mouseover / hover' effect. see jquery code:
$("li.headlink").hover(function(){ $(this).find("a.lightnav").css("display", "none"); $(this).find("a.darknav").css("display", "inline"); },function(){ $(this).find("a.lightnav").css("display", "inline"); $(this).find("a.darknav").css("display", "none"); }); but causing problems. when user moves cursor on image in nav bar current page (ie 'dark' image), removes display attribute set php (obviously).
so need way check on mouseover if 'darknav' has display 'inline' or 'none' , tailor jquery there, life of me cannot figure out how do, i'm not worlds greatest javascript/jquery coder. there way check if element has particular css property applied it, googled , fiddled code hours, no avail.
thanks in advance everyone.
p.s. added css !important in nav bar within php if statement, strange reason, working in chrome, other browsers ignoring rule.
with jquery can check attribute value this:
... code...
alert($(this).find("a.lightnav").css("display")) as far using jquery hide/show elements, use:
$(this).find("a.lightnav").hide() $(this).find("a.darknav").show() no need fiddle "display", it's built-into hide()/show(). should not need use either:
style='display:inline !important'" by default display block or inline, unless you're using "display:none" can lave these out.
if have left-floating menu should using float:left, not display:inline
also inline styles override stylesheet css, should never need use !important.
one hint @ styling menus, style a-tag, not li. put events on tags, not lis.
if want learn how style menus properly, see tutorial: i love lists.
Comments
Post a Comment