Avatar of b2dac
b2dac
 asked on

Scroll <DIV> rows using up and down arrows

Is there a way to scroll a list of rows comprised of DIV tags, using the keyboards up and down arrows? The rows are contained within another DIV tag, which limits the size of the contained DIVs, so the amount of rows usually exceeds the size, so when using the up and down arows the active selection would also need to make sure it is visible. Thanks
JavaScriptHTML

Avatar of undefined
Last Comment
Devario Johnson

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Devario Johnson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
b2dac

ASKER
This is perfect. Thank you!
Devario Johnson

N.p :)
b2dac

ASKER
That's strange I'm getting a 'ScrollTop' is null or not an object error?
Your help has saved me hundreds of hours of internet surfing.
fblack61
b2dac

ASKER
I FOUND THE PROBLEM....(actually 2)

First, there is a variable that is referenced before it is even set. So we must move part of the code up.
FROM:
            // Get the current scroll offset.
            var currentScroll = innerEl.scrollTop;
            var latestScroll = currentScroll;
   
            // Get a handle to the element inside the scrolled element that is our current
            // scrolling target
            var innerEl = document.getElementById(innerElementPrefix + scrollLocation);

TO:
            // Get a handle to the element inside the scrolled element that is our current
            // scrolling target
            var innerEl = document.getElementById(innerElementPrefix + scrollLocation);
                  
            // Get the current scroll offset.
            var currentScroll = innerEl.scrollTop;
            var latestScroll = currentScroll;

Second, I'm using IE7 and the up arrow/down arrow keys were not being detected. To fix this I switched this code:  
FROM: event.which == 63233     (FOR DOWN ARROW)
TO: unicode=event.keyCode? event.keyCode : event.charCode == 40
...and...
FROM: event.which == 63232     (FOR UP ARROW)
TO: unicode=event.keyCode? event.keyCode : event.charCode == 38
b2dac

ASKER
CORRECTION - on the second part of my last post:

THIS: unicode=event.keyCode? event.keyCode : event.charCode

SHOULD BE: event.keyCode
Devario Johnson

cool nice job man
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.