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 7025325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:57:34+00:00 2026-05-27T23:57:34+00:00

I am working on creating a simple site with images running vertically down the

  • 0

I am working on creating a simple site with images running vertically down the page. I would like to be able to smooth scroll between images via the keyboard arrow keys. Through the help of this forum, I have received the following suggestion (which does, indeed, work).

Example: http://jsfiddle.net/aVvQF/5/

Question: How can one smooth scroll up and down between objects on a page with arrow keys?

However, I need a bit of additional functionality. This setup prevents the default action of all keyboard function. I would only like the default action changed for the left and right arrow keys. I decided to use left and right, instead of up and down, so that the standard up and down arrow navigation and page up and page down will not be affected. How can the code change to allow the expected use of all keys except the left and right arrows?

Also, this setup only seems to work if there are no other tags between the ‘img’ tags. However, I need to be able to place links, text and line breaks between or around the images. How can the code be adjusted to allow for this? Or, alternatively, would it work better to put the image and the requisite text and links each in ‘div’ classes running down the page (right now it is all in one ‘div’) and then have the keyboard navigation go between ‘div’s?

Thank you.

  • 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-27T23:57:36+00:00Added an answer on May 27, 2026 at 11:57 pm

    You should do something like below for allowing all other keys except left and right arrow keys at the beginning of your function ->

    var keyCode = e.keyCode;
    
    //return if it is not left/right arrow key
    if (keyCode != 39 && keyCode != 37) {
        return;
    }
    

    I modified your html and script a bit to make it work. See my approach jsFiddle here

    The next() and next([selector]) works differently. The former next simply gets the next sibling, where else the later tries to get the matching list first ($(‘.active’) in your case and picks the next matching element from there (which is 0).

    For example,

     <p class="selected active">Hello Again</p>
     <span class="log" >Test</span>
     <p class="selected">Hello Again</p>
     <div><span>And Again</span></div>
    

    And this $("p.selected.active").next('p.selected') may look like it is going to fetch the next p.selected, but it doesn’t. Looks to me like jQuery iterates through $("p.selected.active") to find matching ‘p.selected’ which is going to return empty.

    I used .next() and added a where clause to find next img tag in the siblings,

     $targetElement = $('.active').next();
    
     while ($targetElement.length != 0 && $targetElement.hasClass('img') == false) {
           $targetElement = $targetElement.next();
     } 
    

    I hope it helps

    Edit:

    Check here.

    1. Add isAnimating flag to avoid spamming of keydown.
    2. Modified css .active img{ border: 2px dotted red; }.
    3. Changed the html a bit.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on creating a simple website for an exhibition. It's intended to use
I'm working on creating a self updating application and one issue I'm running into
I am working on creating a simple contest submission system using django. This is
I've been working on creating a simple IRC bot, which I want to give
I'm creating a simple calculator on VB6. Here's my code I'm working on: textScreen.Text
I'm working on creating a simple MCV application, in order to understand MVC better.
I am working on learning JQuery and creating a simple HTML / JS calculator.
So I'm working on creating a very simple C program that just preforms shell
I am creating an intranet homepage for the company im working at. I would
I'm just building a simple ajax site but running into a problem in safari

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.