-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-anchor] Allow anchoring to pointer #8639
Comments
The syntax allows this. Named anchors require dashed idents, so we can add non-dashed idents to refer to special anchors like this - The layout model should allow it too - pointer position is outside of layout entirely, so in theory it's pipeable into this system without issue. Impl is potentially a different story, since we'd want to make sure it was accurate each frame (rather than lagging a frame behind). @xiaochengh will have to speak to that, for Chrome's impl at least. |
I assume this Performance-wise it means we need a relayout on every pointer move. But maybe in most cases it won't be a big problem, since I assume in most cases the size of the element doesn't depend on pointer location -- in which case we can avoid reflowing the descendants of the element. But still this all seems to be main thread work, and I don't see a possibility of further optimization with compositor. Btw I assume |
Hm, I suppose so. I suppose the CB doesn't actually matter, tho? Maybe we can add a case to the valid-anchor algo that allows for these "no CB at all" cases to be used anywhere?
I'd probably just not allow it in the anchor-size() grammar at all. It'd just be confusing, since either it'd always be 0x0 or it'd always be invalid for sizing and cause fallback. |
For what it's worth, anchoring to the pointer was also suggested by me in #8315 (comment). Sebastian |
There is one important aspect that I think should be mentioned: if we're going to add an ability to attach something to the cursor, I think it would be very important to also be able to attach something to the This would be kinda possible by assigning the If we could come up with something that could allow developers not to forget about the keyboard users when assigning things to the cursor — it would be great! Otherwise, they would need to handle this by themselves somehow, but I'm not yet sure how this would look code-wise. Probably something like using the focus-visible as default (using the center of this element, or something else? Or, If we could somehow combine this into one easy to use thing in CSS, I think it could potentially prevent a number of developer mistakes. We could also still provide an ability to target only the pointer or active element, but the most simple case, imho, should target both. I would also want to provide some other possible use-cases for pointer and/or active-element anchoring:
|
Let's keep this thread to cases where an element tracks the pointer. The ideas where a tooltip follows the pointer, or takes one axis from a pointer and another from an element are fun ideas! |
Re-created this example with buttons on the CodePen with anchor positioning: https://codepen.io/kizu/pen/vYzbqOW Instead of the pointer I'm using an element with relative position, and only use JS to modify its coordinates to “ponyfill” the absence of the actual pointer attachment. The codepen could be probably forked if someone wants to experiment further with the pointer anchoring :) |
In this example I also did add the handling of the |
Right now, if you want to drag an element on the web, you need to listen for
pointermove
events and update the position of the element. This means the operation is bound by the event loop, and can easily jank.It feels like anchoring could solve this, by anchoring to a particular pointer. Then, the element can be moved to a layer in the compositor, and its position can be updated without blocking on the event loop.
The text was updated successfully, but these errors were encountered: