jquery - Add keyboard support to website dropdown navigation -


i know suckerfish well, don't javascript in suckerfish , figured there must easier way using jquery. i've done following page:

    <!doctype html public "-//w3c//dtd html 4.01 transitional//en"        "http://www.w3.org/tr/html4/loose.dtd">     <html lang="en">     <head>     <title>test nav page</title>     <style type="text/css">          html {margin:0;padding:0;text-align:center;font-size:62.5%}         body {margin:0 auto;padding:0;width:600px;text-align:left;}          ul#nav {display:inline-block;width:260px;border:0;float:right;list-style:none;position:relative;}             ul#nav li {display:inline-block;float:left;width:130px;font-family:arial;color:#444;font-size:1.2em;font-weight:bold;text-align:center;position:relative;}             ul#nav li.t1, ul#nav li.t1 ul li {background-color:#aad;}             ul#nav li.t2, ul#nav li.t2 ul li {background-color:#daa;}                 ul#nav li ul {position:absolute;left:-9999px;display:block;width:130px}                     ul#nav li:hover ul,ul#nav li.hover ul, ul#nav li:focus ul {left:-40px;}                  ul#nav li {display:block;width:120px;padding:7px 5px;}                     ul#nav li ul li {border-top:solid 1px #ddd;font-size:0.9em;padding:7px 0;width:130px;display:inline-block}       </style>     </head>     <body>         <ul id="nav">             <li class="t1"><a href="#top1" tabindex="1">top one</a>             <ul>                 <li><a href="#first" tabindex="2">first</a></li>                 <li><a href="#second" tabindex="3">second</a></li>             </ul></li>             <li class="t2"><a href="#top2" tabindex="4">top two</a>             <ul>                 <li><a href="#third" tabindex="5">third</a></li>                 <li><a href="#fourth" tabindex="6">fourth</a></li>             </ul></li>         </ul>         <script type="text/javascript" src="js/jquery.min.js"></script>         <script type="text/javascript" >         $(document).ready(function(){             $('ul#nav li').hover(                 function(){                     $(this).toggleclass('hover');                 }); // updated following jquery function...             $('ul#nav li a').focus(             function(){                 $(this).parent().addclass('hover');         }); // need way of closing dropdown when key focus moves out of li, not anchor...         });         </script>     </body>     </html> 

and works great except it's inaccessible keyboard. can point out i'm missing!? it's baffling me, been @ past 2 hours , getting fast.

cheers,

t

update: i'm close! i've added jquery function applies "hover" class parent li if focus on anchor tag. i've added in code above. allow me tab onto link , shows dropdown links, once tab past (i've updated tabindex) won't disappear.

t

try following

        <script type="text/javascript" >     $(function(){       //for ie6       $('#nav li').hover(function(){ $(this).addclass('hover') }, function(){$(this).removeclass('hover')});        $('#nav a').focus(function(){         $(this).parents('li').addclass('hover');       });        $('#nav a').blur(function(){         $(this).parents('li').removeclass('hover');       });     })     </script> 

note: changed toggleclass because don't trust it. think should specify want happen class otherwise risk getting stuck in state didn't expect.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -