Reputation: 4511
Looks like a widely covered topic, but I still can't get it work for the given a case. I am implementing arrow up/down handler for my table, and here's my code:
$(document).on('keydown', 'tr input', function (e)
{
switch(e.which)
{
// ...
case 40: // down
e.preventDefault();
target = some_element;
if ($(window).height() - target.offset().top < SCROLL_DELTA)
{
$(window).scroll(); // I thought this would make my window
// scroll down one step, but this does not happen
}
// ....
Just to clarify. I have a table with inputs inside td's. As the user presses arrow-down, he walks through the inputs. Browser does not automatically scroll down as the user reaches the zone which is outside the viewscope of the screen, and I have to bother about it myself. So my goal is to scroll one step when the user reaches an input which is near the page bottom. So the quesiton is, what should I write instead of $(window).scroll() to make it work ?
Upvotes: 0
Views: 455
Reputation: 2047
You can do it with window.scrollTo(x,y)
function
for more details read MDN
Upvotes: 1