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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:40:47+00:00 2026-05-12T07:40:47+00:00

I am using jQuery’s scrollTo plugin to scroll up and down my page, using

  • 0

I am using jQuery’s scrollTo plugin to scroll up and down my page, using UP arrow and DOWN arrow.

i have a bunch of div with class “screen”, as so: <div class="screen-wrapper">...</div>

What I am trying to do is, when i press UP or DOWN, the window scrolls to the next, or previous div with class of “screen”.

I have the keypresses taken care of.
According to the plugin docs, to scroll a window, you use $.scrollTo(…);

Here’s the code I have:

$(document).keypress(function(e){
    switch (e.keyCode) {
        case 40:    // down
            n = $('.screen-wrapper').next()
            $.scrollTo( n, 800 );
          break;
        case 38:    // up

          break;
        case 37:    // left

          break;
        case 39:    // right

          break;

    }      
});

And if it helps, here’s the HTML div. I have a few of these on the page, and essentially, am trying to scroll to next one by pressing down arrow:

<div class='screen-wrapper'>
<div class='screen'>
    <div class="sections">
        <ul>
            <li><img src="images/portfolio/sushii-1.png " /></li>
            <li><img src="images/portfolio/sushii-2.png" /></li>
            <li><img src="images/portfolio/sushii-3.png" /></li>
        </ul>
    </div>

    <div class="next"></div>
    <div class="prev"></div>
</div> 

And also if it needed, I can provide a link where this is being used if it’ll help someone get a better idea.

edit
And, i forgot to mention what the real question here is.
The question/problem is that it won’t scroll down past the first element, as seth mentioned.

  • 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-12T07:40:48+00:00Added an answer on May 12, 2026 at 7:40 am

    There’s no real question here but I’m going to guess the problem is that your page doesn’t scroll past the first one. It’s because you call this on every keypress:

                n = $('.screen-wrapper').next()
    

    It’s probably returning the same one every single time you call it. Try moving the instantiation outside of the keypress.

              var s = $('.screen');
              var curr=-1, node;
    
              $(document).keypress(function(e){
                 switch( e.keyCode ) {
                   case 40:
                      node = s[++curr];
                      if (node) {
                        $.scrollTo( node,800);
                      }
                      else {
                        curr = s.length-1;
                      }
                      break;
                    case 38:
                       node = s[--curr];
                       if (node) {
                         $.scrollTo( node ,800);
                       }
                       else {
                          curr = 0;
                        }
                       break;
                    }
              });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 483k
  • Answers 483k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take look at asort(): This function sorts an array such… May 16, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer Practically all of the PC/desktop/laptop users have JS enabled. Your… May 16, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer Well, the regex "\d{2}\.\d{2}\.\d{4}" should work - but it won't… May 16, 2026 at 7:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.