mzubala / jquery-custom-scrollbar

189 stars 102 forks source link

Keyboard scroll fires even when element is not focused and hovered by another element #10

Closed ekzobrain closed 11 years ago

ekzobrain commented 11 years ago

For keyboard scroll to work keydown and mousemove events are bound to the DOM and mouse position is determined with the help of isMouseOver() function, the logic of which is very pure because element may be hovered by some overlay, but it will still be subject to scrolling. I think logic should be like this: we capture mouseover/mouseout events (with jQuery hover() method) on scrollable element and when it is hovered - we start capturing keydown events on document. When element recieves mouseout - we remove keydown listener, because there's no need to capture theese events then. Also, keyboard scroll should be disabled when form elements recieve focus inside scrollable area, because they also use up/down keyboard buttons and container shouldn't be scrolled then. And this functionality should be totally disabled for mobile devices, because they don't have any keyboard anyway :) there's only one way of scrolling - touch.

ekzobrain commented 11 years ago

I think even better decision is like this: we attach keydown event to scrollable element itself. Then when element is hovered we focus/blur it (of course element should be focusable, it cat be achieved by setting negative tabindex to it). So element can trigger keydown events. And also this automatically solves problem of inner form elements and nested scrollbars. But before setting focus to element we should first check wheater some form element on the page is focused and cancel mouseenter event if so.