Firefox has a behavior where, if you click on a scrollable div, then that div responds to all the mousewheel and the Page Up/Down keys, effectively making it “focused”. However, the HTML5 spec dictates that divs cannot be “focused”, technically. Therefore, even though the div receives keyboard and mouse events, it’s not reported in document.activeElement or a DOMActivate event handler.
So how can I detect when a scrollable div has scrolling focus in Firefox? Here’s a test page. Oddly, the div is reported in document.activeElement when you tab into it, but that’s the only time that happens. A workaround might be to listen for click and scroll events instead, but I’m not sure if that’s the best solution?
EDIT: This is for a Firefox extension, so any chrome-level JS would be acceptable. This also means I can’t edit or predict how certain pages are coded.
If you assign the
<div>atabindexattribute/property (you can set it to0to make it focusable in the normal flow of the document, or-1to remove it from the normal tab flow entirely), then it can firefocusandblurevents. Some simple CSS can eliminate theoutlineif you find it undesirable, but it may be desirable for usability reasons.