-
Notifications
You must be signed in to change notification settings - Fork 661
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-transitions] Transition to height (or width) "auto" #626
Comments
Adding here what I replied to @keithjgrant via Twitter: In order to interpolate to/from an Sure, there are edge cases where the performance would inevitably be horrible (e.g., if you are transitioning to/from |
@keithjgrant yes, this is a real problem. For the moment, we set up transitions on max-height value (using magic numbers for values, max-height = enough_and_pray_the_content_is_not_that_tall), and if you want to do it including accessibility pov, you have to transition on visibility (as display is not possible, cf this accordion https://a11y.nicolas-hoffmann.net/accordion/?animated=1 ) with a delay... really complicated for something that should be simple. :) |
Looking around the web, you can easily see that this is a constant problem for developers. Velocity.js even notes this specific missing feature in its first paragraph of why it exists (https://fabric.io/blog/introducing-the-velocityreact-library). I can probably give a ton of references (on request) of developers rendering an element, measuring it, setting it's height to 0 then animating to that specific height. Even JQueryUI does a similar measurement technique just to get this to work and it's been around for almost a decade now. What can we do as the larger software development community to petition this change and make sure it gets in on the next iteration? Do we need to have more people come here and upvote this bug? Do we need to email a specific individual? Let us know so we can let you know what we need most. |
I too am curious what we (the web programming community in general) can do to petition a change in the spec... I've got a few issues I know I could get quite a few people backing. |
I caught up with @dbaron about this recently and it seems a likely way forward is to make 'auto' into a computed value. As well as enabling animation with (One way to push this forward would be to submit a patch to one of the open-source browsers for this. Once you've proven the technical feasibility of this, it's easier to argue for it to be added to the spec.) |
|
Awesome I'll start looking into it using Firefox since I think theirs would be the easiest source code to get a hold of. That said, it may take me a while due to lack of cpu resources (my computer is a 2 core 2.4ghz processor... it's going to take a while to build). |
Thank you very much for bringing this up. We currently work around this by reading out an elements |
It has been suggested that we use But trying to get the browsers to implement either has been very difficult, as the CSS animations are typically done between 2 known values, which is why animation usually needs to be done with something like As an aside (and for some of the background on this), I've been trying to get browsers to support auto-height https://github.com/craigfrancis/iframe-height https://discourse.wicg.io/t/feature-request-animating-max-height-height-based-on-content/1403 |
+1. Not being able to transition on |
Just FYI I'm currently out of the country and I'm also checking with my legal department to see if this is something I'm allowed to do due to where I work (non-compete and helping competitor issues). I'll be back in town on the 20th. @nilssolanki That's the same trick we're using and it's just annoying. @Jakobud I would say animating display is a bit out of the bounds of this request and may also have a few edge cases that would be interesting (animating inline to block?). |
My legal department has come back to me informing me that I'm unable to currently work on this request due to non-compete legal stuff. That said, I'll have to (frustratingly) recuse myself of any code writing for this feature. Just to note, I also asked a google groups question here if anyone is interested in taking this up. It should give a basic guide to how I was planning on tackling the problem. |
Just want to make sure this is still happening. This is actually rather important because, yes, we can precalculate a value for height and other properties using javascript and things like For example, I have an element that transitions from a height of 0 to a height of 'auto'. After the transition is completed I want the height of the element to be able to adjust correctly to the changing elements inside of it without me having to recalculate it myself. So if it really is just adding |
To my knowledge no one has picked up this work and I'm still barred due to legal constraints. But if you download the source code and read the conversation here: It should give you a few locations to pinpoint where you would need to make the changes you need. Not sure if those are all of them but it should give you a starting point for learning the code base. Good luck, I hope you do take this up because it would be an amazing addition! |
I'd have to review to make sure that 'auto' doesn't have any special behaviors that make it incompatible with explicit lengths in some situations. That is, any place where the layout system does special things if the width/height is "auto", such that replacing the "auto" with its equivalent absolute length would give a different result. |
I can't remember the source, but it was recommended we use Where it would be nice if we could use this keyword for iframe's and textarea's as well. |
@k2snowman69 I would love to take this on and get it done. My question is what all would I need to change? I understand that there are the specification pages that explain how the transitions should be interpolated, and that those should be changed if this is added, but is there also some actual coded function or set of functions that would need to be modified? If so, where can I find them? @tabatkins Do you know of any situations where that would be the case? (that auto acts differently than it's explicitly stated px size?) |
How can I transition height: 0; to height: auto; using CSS? is currently the top-voted question in the Also, what's the story with bugzilla these days as far as CSS? There's this bug - pointed here. |
While height is easy to get to the calculated auto through max-content, it would be best if this were to work for multiple properties such as width (there is no setting comparable to auto) and others. It is impossible to use javascript to get width to work properly without manually doing the math to remove the L&R margins, padding, and border from the 100% calculation, and other properties have similar setting problems. Using the pre-calculated auto value as the target setting for each property that has an 'auto' option, while actually setting it to 'auto', would be the best method from what I can see. PS: The data from Stackoverflow suggest that this is the most requested feature for the next CSS update. Using Stackoverflow's highly voted issues would probably be a good place to look for other features that might be good to include in the next version. |
I used to really really want this feature, but over the years have found myself being content with transitioning a transform in many cases, while having a parent element set in inaccessible ways... .parent {
pointer-events: none;
visibility: none;
overflow: hidden;
}
.element {
pointer-events: auto;
visibility: visible;
transition: transform ease .375s;
will-change: transform;
}
.transformed .element {
transform: translateY(-100%);
} Here, the |
@jonjohnjohnson do you have a codepen/jsfiddle example of this anywhere and if not would you mind posting an example here? Many thanks |
@cohsteve Quick -> https://jsfiddle.net/rwozw4bs/ Also, read up on FLIP animation methodology to see how you *could approach animating transforms while simulating the movement of flow content. https://aerotwist.com/blog/flip-your-animations/ |
@jonjohnjohnson A transform effect works for absolutely positioned elements. But if the element is statically positioned, it still takes up space in document flow when scaled down to height 0. Transitioning |
@keithjgrant correct. I find the gains from transforming a texture and not invalidating layout worthwhile, as opposed to the *few times I find myself wanting to animate within a flow. |
Just making sure that this project hasn't been abandoned. @dbaron, I see you are also the one assigned to the Mozilla ticket as well? (https://bugzilla.mozilla.org/show_bug.cgi?id=571344) (I don't mean to be so pokey about this. I just keep running into designs where having this would immediately make the desired-but-impossible possible. So I hope that a fix for this bug will come soon.) |
This comment has been minimized.
This comment has been minimized.
I had the feeling that after 8 years of discussion, we're finally touching the root of the problem. But, alright, I'll mute. |
The problem is not just with the "trigger". The problem is that interpolations are currently based on computed values, and you want to interpolate used values instead. As I have said several times in this issue, that's an entirely different model, that would need to be properly defined. |
I once again submit the suggestion to create a keyword similar to It doesn't need to be exactly the same as |
At this point, we've gone in circles on the fundamental limitations that make this difficult. We know the goal, and we have ways of achieving it. We just need to pick one. Of the suggestions, either we create a clunky and unintuitive partial (no auto to auto) solution by adding functions that interpret I am still in favor of the latter. |
Where did anyone with sufficient knowledge of the CSS specs claim this was possible? 🤔 |
Yes, let's please close down this thread of conversation. The use-case in the OP has been solved, and this additional use-case, if it's solveable at all, requires a substantially different effort. This issue is not the appropriate place to discuss that. |
[removed original] I'll just put the suggestion in a different thread. I just realized that we can "why not both?" these ideas. I'll also take the time to make sure that my proposal is clear and detailed, and not just vague and poorly worded as I have done in this thread. Thank you all for the help, and I look forward to the existing proposal being implemented. |
The question came up a number of times earlier in the discussion: why not just support animation from keywords to lengths? I said that I'd do a bit of research on the compatibility of doing this and report back. I think at this point I've done sufficient research to determine that supporting animation between width keywords and lengths/percentages isn't web compatible. How did I determine this? In addition to the work I've been doing on I also wrote a CL to gather data on sites that hit this codepath and an additional CL to print out some diagnostics when this happens. I used cluster telemetry (see second doc) to use the first of these CLs to gather data on which sites in a list of top 1000 sites hit my counter on loading. I then used the second CL, combined with devtools, to try to understand what part of the site was hitting the counter and whether there were visible regressions from enabling transition/animation support between these values. Note that this technique was not foolproof -- sometimes I might just fail to see the visual difference even if one was present, or even fail to figure out the right elements to look at. I didn't go all the way through the list of sites that hit my counter, but I went partway through (see full data below). The full data I have are in this hand-edited CSV file with my notes for the ones that I analyzed. (expand for details)
Note that this is a very conservative sample because it only looks at loading of site homepages. Many transitions and animations happen in response to user interactions, and happen on pages other than the homepage. I found the following site homepages that showed visible differences when enabling transitions and animations between sizing keywords and lengths/percentages:
The first and fifth issues above (and perhaps also the third, but it's less visible on the home page because it happens only below the fold) might be close to bad enough to mean we'd have to revert the feature if we tried to ship it. However, more significantly, I think this list of issues suggests there's a long tail of many more issues across many other sites that I didn't examine, which I think makes it clear that we couldn't just ship support for transitions/animations between sizing keywords and lengths/percentages, and that it has to have some sort of opt-in (which, in the current proposal, is use of the |
Thank you so much for the exploration, @dbaron ! That's more than I expected! I agree, then - while the results are mixed, there's enough obvious bad results that it seems like a net negative to have this operate by default. I plan to keep the current spec as it is, then, where you need at least one of the transition endpoints to be a |
Agenda+ just to confirm with the group that, per dbaron's research, supporting direct " (But the syntax is designed such that you can literally just slap the |
The CSS Working Group just discussed
The full IRC log of that discussion<khush> > if that returns pseudo-element animations?<khush> flackr can confirm. I think it's supposed to. <fantasai> -> https://github.com//issues/626#issuecomment-2071016522 <fantasai> dbaron: We discussed calc-size() proposal. One question was whether we could, instead of or in addition to calc-size(), write what people want to write <fantasai> dbaron: concern was compat, but did we check <fantasai> dbaron: one thing I followed up with, since I had implemented, I could implement the natural behavior where you could just transition '0x' to 'auto' <fantasai> dbaron: I could figure out what could break <fantasai> dbaron: There's more details in the comment in the issue, but basically what I did was a very conservative study <fantasai> dbaron: ran through loading top 1000 sites with a special build <fantasai> dbaron: Even with that limit, I found multiple pages that would break with this change <fantasai> dbaron: [gives some examples] <fantasai> dbaron: Several pages animating widths and heights from zero that was not expected <fantasai> dbaron: at the same time, there was a page on ups.com with an animation that got better <fantasai> dbaron: but conclusion was, given this very small and conservative sample shows multiple pages that are broken <flackr> q+ <fantasai> dbaron: we know it's not web-compatible <fantasai> dbaron: so we know we can't just support CSS tranistion from 0px to auto and equivalents <fantasai> dbaron: given that, what I want to get out of this is to restate more firmly that we want to move forward with calc-size() <fantasai> dbaron: given alternative, which would have better developer ergonomics, is not compatible <astearns> ack flackr <fantasai> flackr: agree we can't just do it automatically <fantasai> flackr: what about having a more generic opt-in for authors? <fantasai> flackr: calc-size() require for each item to change the styling <fantasai> flackr: whereas a switch could opt in your whole page <fantasai> dbaron: we could consider something like that <fantasai> dbaron: maybe use transition-behavior, which is designed to do that <fantasai> dbaron: it's reset by the transition shorthand <fantasai> flackr: it's also about transitions only, not animation <fantasai> dbaron: I think we can do both <fantasai> dbaron: current behavior with calc-size(), to get the animation you have to wrap at least one endpoint in calc-size() <fantasai> dbaron: I also do worry about global overrides <fantasai> dbaron: because pages are built from smaller components <astearns> ack fantasai <fantasai> fantasai: Agree with flackr <TabAtkins> I'm completely fine with a value that can turn on the transition behavior for general values, fwiw, so long as the default behavior requires using calc-size() on at least one side. <fantasai> fantasai: I think putting in transition-behavior is good, not global, easy to incorporate into transitions and gets reset whenever you do a different ransition <fantasai> fantasai: for animations, could consider something in the @Keyframes rule, so that it gets associated with the keyframes and used wherever the keyframes get used <fantasai> astearns: but agree that doesn't preclude using calc-size() <fantasai> fantasai: yes <fantasai> TabAtkins: Proposed resolution, by default, only get transition if at least one side gets calc-size() <fantasai> RESOLVED: Animation to/from keyword sizes requires an opt-in, so by default only get transition ifa t least one side gets calc-size() <fantasai> s/ifa t/if at/ <fantasai> dbaron: At this point it's prototyped in Chromium, but it's getting more stable and closer to matching spec at this point |
Can you do |
No. In terms of the spec (defining that you can't do it), you can't because In terms of rationale (why shouldn't it be allowed), it's because many layout algorithms in CSS depend not just on the mathematical values of these properties but also have conditionals that branch on what are essentially type checks on the value. This alternative is a bit less general than allowing full
|
I wonder if it would be more web-compatible to only transition between these values when a |
So looking at the sites that were problematic at the time (today there would likely be new sites showing up as problematic in addition to old ones dropping off the list):
So I don't think that helps sufficiently. (Remember also that this is from a sample of loading homepages without any user interaction, which in general doesn't trigger that much animation compared to the animation that results from user interactions.) |
I've been looking at making My current understanding of the algorithm is (when adding support for these new things) the base sizes set up in the "Initialize Track Sizes" step don't really matter, and there's no need to adjust what happens in which step beyond being clear that I'd appreciate if someone who knows grid could double-check this, though. Edit: I realize the above is wrong because it doesn't consider tracks that have no items! So I think "Initialize Track Sizes" does need to be adjusted. |
This adds calc-size() support to the grammar productions for width/height and min/max-width/height, which also implies adding them to the productions for block/inline-size and min/max-block/inline-size and to flex-basis. This is part of w3c#626.
…x-width/height. (#10628) * Add calc-size to productions for width/height and min/max-width/height. This adds calc-size() support to the grammar productions for width/height and min/max-width/height, which also implies adding them to the productions for block/inline-size and min/max-block/inline-size and to flex-basis. This is part of #626. * Improve linking and reorganize a little bit.
(Edited: current resolved-on proposal is at #626 (comment))
https://drafts.csswg.org/css-transitions/#animtype-rect
It would be incredibly useful to be able to transition to (or from)
height: auto
. As it stands now, you need to jump through a bunch of hoops in JavaScript to simulate it. This is used frequently for transitioning in alert boxes, opening accordions, etc, but it seems silly that JavaScript is required.I’m sure there must be discussion about this in the old mailing list, but I’d love to be privy to it here.
The text was updated successfully, but these errors were encountered: