aframevr / aframevr/aframe

A-Frame mouse and touch controls don't work when <a-scene> z-index is negative

Open
#4,914 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
17.6k
Forks
4.4k
PR merge metrics
No merged PRs in 30d

Description

Description:

A-Frame help here discusses the use of z-index as a way to layer 2D UI elements over an A-Frame scene.
https://aframe.io/docs/1.2.0/components/embedded.html#integration-with-the-2d-page

However based on this advice there is a chance that someone might be inspired to set the z-index of their to a negative value (which is exactly what I did).

Having done that, they will then discover the unfortunate side-effect that mouse & touch controls can no longer be detected in the A-Frame scene, as demonstrated in this glitch.
https://adaptable-quick-dedication.glitch.me/
(press the button 3 times to get to negative z-index values).

I don't understand the root cause, but have observed that when "a-scene" z-index is 0 or higher, then setting a breakpoint onto mouse or touch events in the Chrome debugger reveals various events being triggered on CANVAS. And when z-index is < 0, no events are triggered on CANVAS.

I doubt anyone has a genuine reason to need their "a-scene" to have a negative z-index, but at a minimum this issue should be documented at the docs link above.

It would be nice to have a fix, as even with documentation it will be easy to stumble across this, and the consequences might not be obvious (for me, I was trying to troubleshoot why raycasting wasn't working, and after several hours I finally realized that it was down to this).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Glitch reproduction and verify mouse and touch behavior while changing the a-scene z-index from 0 to a negative value. Read the linked embedded-scene documentation and investigate why canvas events stop firing; done means either the controls work with a negative z-index or the limitation is clearly documented there.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.