javascript - Navigate to specific anochor tag via up and down arrow press -



javascript - Navigate to specific anochor tag via up and down arrow press -

i using anchor tags , have implemented smooth scrolling on 5 links. works perfectly. however, add together ability utilize arrow keys navigate through these same anchor tags.

i can fumble through javascript , jquery, i'm pretty confused when comes stuff.

<ul> <li class="scrolldot"><span><a href="#one">1</a></span></li> <li class="scrolldot"><span><a href="#two">2</a></span></li> <li class="scrolldot"><span><a href="#three">3</a></span></li> <li class="scrolldot"><span><a href="#four">4</a></span></li> <li class="scrolldot"><span><a href="#five">5</a></span></li> <li class="scrolldot"><span><a href="#six">6</a></span></li> </ul>

so basically, want user nail downwards arrow , them taken next section, depending on over page. if on section 2, take them three. if nail again, taken 2 , forth. create sense?

checkout mousetrap. it's nifty little library makes binding keys pretty easy. there few examples on site well.

perhaps suffice:

mousetrap.bind('up', function() { your_up_function(); }); mousetrap.bind('down', function() { your_down_function(); });

javascript smooth-scrolling keyboard-navigation

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -