Skip to content

Introduce a mechanism for using an attribute value as a variable #2931

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

Closed
Zhang-Junzhi opened this issue Jul 17, 2018 · 1 comment
Closed

Comments

@Zhang-Junzhi
Copy link
Contributor

Zhang-Junzhi commented Jul 17, 2018

For now, we are able to design an adaptive UI using attribute-selectors if the possible values of the attribute is enumerable, but there's no way to deal with the situation where the possible attribute values are innumerable.

For example, if I am going to design a positioned box that always follows my cursor by a fixed distance, the current solution is likely to listen to the mousemove event of the window in script code, and do real-time caculation and adjustment for the element.style.left, element.style.top of the box based on the position of the cursor. But that doesn't seem a perfect solution as script code is not primarily used to care for or directly meddle with the style of the document, it would be better if the script just manipulates DOM attributes, and lets presentation up to CSS according to the attribute values.

With the ability of using an attribute value as a variable, this can be achieved. We can set the cursor position value to data-current-cursor-x and data-current-cursor-y attributes on html or body using script, and get the values of the two attributes for use in CSS's calc function.

Although an attribute is always a string, there has to be different kinds of CSS variables it can be converted to(e.g. a number with/without a unit, or just a pure string), in different situations. Currently I haven't come up with a specific solution as to the design of the new mechanism. I just propose for the general idea of using an attribute value as a variable.

@Zhang-Junzhi
Copy link
Contributor Author

I just saw attr() in https://www.w3.org/TR/css-values-3/#attr-notation , :)
Great! Please close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant