V
V
Vladislav2015-10-16 15:08:35
JavaScript
Vladislav, 2015-10-16 15:08:35

How to simulate pressing the "down" and "up" buttons when the input is selected?

There is an input on the page, it is in focus, is it possible to somehow perform the default scrolling of the page when the user presses "down" and "up"? Of course, I can simply increase or decrease the scroll when these buttons are pressed, but I wonder if it is possible to somehow simulate the default browser event. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2015-10-16
@IonDen

You can jsfiddle.net/oxjaoLas

var $win = $(window);

$('.inp').on('keydown', function (e) {
  switch (e.which) {
        case 38:
            var top =  $win.scrollTop();
            top -= 10;
            $win.scrollTop(top);
            
            break;
        case 40:
            var top =  $win.scrollTop();
            top += 10;
            $win.scrollTop(top);
            
            break;
    }
});

But why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question