Edgar Navasardyan Edgar Navasardyan - 1 year ago 82
jQuery Question

Trigger window scroll in Jquery/JS

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)
// ...
case 40: // down
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 ?

Answer Source

You can do it with window.scrollTo(x,y) function

for more details read MDN

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download