Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:05:43+00:00 2026-05-27T22:05:43+00:00

The website in question: http://harrisonfjord.com/folio2/ As you can see, there is a menu at

  • 0

The website in question:

http://harrisonfjord.com/folio2/

As you can see, there is a menu at the bottom which uses jquery scrollTo to move up and down the page. The menu code is:

<ul id="menu" style="list-style:none">
        <li><a href="#" class="current" onclick="jQuery.scrollTo('#home', 1000 )"><img class="hoverImage" src="img/home_highlight.png"/></a></li>
        <li><a href="#" onclick="jQuery.scrollTo('#asics', 1000 )"><img class="hoverImage" src="img/asics.png"/></a></li>
        <li><a href="#" onclick="jQuery.scrollTo('#tooheys', 1000 )"><img class="hoverImage" src="img/tooheys.png"/></a></li>
        <li><a href="#" onclick="jQuery.scrollTo('#olympics', 1000 )"><img class="hoverImage" src="img/olymp.png"/></a></li>
        <li><a href="#" onclick="jQuery.scrollTo('#panadol', 1000 )"><img class="hoverImage" src="img/panadol.png"/></a></li>
        <li><a href="#" onclick="jQuery.scrollTo('#plants', 1000 )"><img class="hoverImage" src="img/plantsplus.png"/></a></li>
        <li><a href="#" onclick="jQuery.scrollTo('#kia', 1000 )"><img class="hoverImage" src="img/kia.png"/></a></li>
    </ul>

There are two elements at play here. First, clicking the li.a uses scrollTo to go up and down the page. Second, hovering/clicking on the images toggles a “_highlight.png” source change, as follows:

// MENU HOVER IMAGE:
$(function () { 
    $('img.hoverImage').mouseover(function () {
        if ($(this).is('.activeImage')) return;
        var src = $(this).attr("src").match(/[^\.]+/) + "_highlight.png";
        $(this).attr("src", src);
    }).mouseout(function () {
        if ($(this).is('.activeImage')) return; // Skip mouseout for active image
        var src = $(this).attr("src").replace("_highlight", "");
        $(this).attr("src", src);
    }).click(function () {
        // remove previous active state
        $('.activeImage').not(this).removeClass('activeImage').trigger('mouseout');
        // set new active state
        $(this).addClass('activeImage');
    });
});

This all works fine. However, when I try to add keyboard controls to the page, the whole thing falls apart. I’d like to use up/down arrows to move to the previous/next menu items, which uses the following code:

// Add "current" class to #menu links when clicked

$("#menu a").click(function(e) {
    $(".current").removeClass("current");
    $(this).addClass("current");    
});


// CONTROL BOTTOM MENU WITH UP/DOWN ON KEYBOARD

$(document.documentElement).keyup(function (event) {
  // handle cursor keys
  if (event.keyCode == 38) {
    // go up
    $("a.current")
      .parent() // moves up to the li element
      .prev() // moves to the adjacent li element
      .find("a") // moves down to the link
      .click(); // triggers a click on the previous link
  } else if (event.keyCode == 40) {
    // go right
    // same as above, but just on one line and next instead of prev
    $("a.current").parent().next().find('a').click();
  }
});

This works, however (obviously) this triggers the click event which does not successfully toggle the _highlight.png function. What’s the best way to go about changing the code so that the keypress event not only scrolls to the correct div, but also highlights/un-highlights the correct menu items?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:05:43+00:00Added an answer on May 27, 2026 at 10:05 pm

    The short, and almost needs more work, answer:

    $(function() {
      function highlight(e) {
        var _this = $(this),
            src = _this.attr("src").replace("_highlight", "").slice(0, -4) + "_highlight.png";
    
        _this.attr("src", src);
      }
    
      function refresh() {
        $("#menu a img").each(function(e) {
          var _this = $(this),
              src = _this.attr("src").replace("_highlight", "");
    
          _this.attr("src", src);
        });
    
        highlight.call($("#menu a.current img"));
      }
    
      function scroll(item) {
        jQuery.scrollTo(item, 1000);
    
        // Add "current" class to appropriate link
        $("#menu a").removeClass("current");
    
        var link = $("#menu a[href=" + item + "]");
        link.addClass("current");
    
        refresh();
      }
    
      $("#menu a").click(function(e) {
        // Pull the hash URI from the href.
        scroll($(this).attr('href'));
      }).find("img").hover(highlight, refresh);
    });
    
    // CONTROL BOTTOM MENU WITH UP/DOWN ON KEYBOARD
    
    $(document).keyup(function(e) {
      var p = $("a.current").parent();
      if (e.keyCode === 38) {
        p.prev().find("a").click();
      } else if (e.keyCode === 40) {
        p.next().find('a').click();
      }
    });
    

    The longer answer: abstract, use idempotent methods, and I’ll be back later to give a full rundown of the strategies used in here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The website in question is http://oxfordbeach.com/bynight/ If you resize the browser, the nav bar
In a recent question I asked I was directed to this website: http://developer.android.com/design/index.html Amazing
Website test page: http://www.lantiis.com/indexold.html jsFiddle: http://jsfiddle.net/Guhb4/7/ I received help with the jQuery and it
one more question. This is the website: http: //www.revewit.com/ Check out input field on
Accodring to information on jScrollPane website (http://jscrollpane.kelvinluck.com/iframe.html) you can use it only with iframes
The website of the statistics generator in question is: http://gitstats.sourceforge.net/ Its git repository can
From this question:- https://stackoverflow.com/questions/1342611/is-there-a-webservice-api-to-grab-a-screenshot-of-another-website and some other questions/google I got some results like:-- http://www.bitpixels.com/
I have a problem. I'm trying to integrate jQuery address http://www.asual.com/jquery/address/ into my website.
This is a demo website: http://reddledemo.wordpress.com (No, this is not a WordPress-related question.) What
I'm building this website and I have basically two questions about this page: http://sites.publishyours.com.br/silviamecozzi/pt/obra/deserto_das_palmas.php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.