1

I have a page with a scrollable element. My problem is that I want the up/down arrows to scroll this element even if it does not currently have focus.

I'm trying to just trigger a keydown with the same event when any keydown event is detected outside the target element.

$(document).keydown(function(e) {
  if ($(e.target).hasClass('box')) {
    return;
  }
    $('.box').trigger('keydown', e);
})

See this JS fiddle: https://jsfiddle.net/4tx6aqrr/2

This is not working. Is what I want to do possible?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Chris
  • 6,076
  • 11
  • 48
  • 62
  • 1
    You can move the element manually using `scrollTop()`: https://jsfiddle.net/4tx6aqrr/3/. I haven't posted this as an answer as it's not really an ideal solution. `trigger()` doesn't seem to want to play ball. – Rory McCrossan Nov 18 '16 at 11:38
  • Thanks, I've adapted this approach, yeah it's a bit hacky but does the job. – Chris Nov 18 '16 at 14:14

0 Answers0