-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Use translate3d() #1380
Use translate3d() #1380
Conversation
My two cents would be to use properties what they were intended for (so translateX/Y for 2D translations and translate3d for 3D translations). I'm not an expert, but |
That's a fair point, maybe this should exist as an option in
and
Although I'd argue that the
|
Gathering some feedback here then can decide if we should merge this 👍 |
Commenting here as well for those that don’t see the Twitter thread. This link compares performance for both |
I would just use <div class="enable-gpu">
<div class="transform translate-y-6">
</div> .enable-gpu {
transform: translateZ(0); /* equivalent to translate3d(0, 0, 0) */
} Some developers might prefer a toggle in tailwind.config.js, like @slavanossar mentioned, but a global toggle might not be the best for everyone. Maybe we could have both? |
This is an important consideration as well (caused by the GPU rendering things differently): https://twitter.com/krijassnica/status/1280909655879880704. More information here: https://frippz.se/2016/02/04/fixing-blurry-text-on-hardware-accelerated-elements/ Lastly, like Donald Knuth stated: "premature optimization is the root of all evil". 🙂 |
I think having both would be a bad idea. Tailwind is nice for its defaults, and people can always extend the config as they wish. |
I came across such an issue because I wanted to move a big background-image with transform: background-position. Turns out to be a very bad idea, it stutters and the browser couldn't handle it. Tried translateX/translateY, but there was some stutter left, but better performance in general. I got it completely fixed with transform3d and the will-change property, because of hardware acceleration with transform3d and performance optimizations with will-change. Good article about will-change |
Having thought about this some more, I think this would be better solved by just having a For anyone who wants to create their own: /* utilities.css */
.transform-gpu {
--transform-translate-x: 0;
--transform-translate-y: 0;
--transform-rotate: 0;
--transform-skew-x: 0;
--transform-skew-y: 0;
--transform-scale-x: 1;
--transform-scale-y: 1;
transform: translate3d(var(--transform-translate-x), var(--transform-translate-y), 0) rotate(var(--transform-rotate)) skewX(var(--transform-skew-x)) skewY(var(--transform-skew-y)) scaleX(var(--transform-scale-x)) scaleY(var(--transform-scale-y));
} EDIT: changed |
Since you are using .transform-gpu {
--transform-translate-x: 0;
--transform-translate-y: 0;
--transform-translate-z: 0;
--transform-rotate: 0;
--transform-skew-x: 0;
--transform-skew-y: 0;
--transform-scale-x: 1;
--transform-scale-y: 1;
--transform-scale-z: 1;
transform: translate3d(var(--transform-translate-x), var(--transform-translate-y), var(--transform-translate-z))
rotate(var(--transform-rotate))
skew(var(--transform-skew-x), var(--transform-skew-y))
scale3d(var(--transform-scale-x), var(--transform-scale-y), var(--transform-scale-z));
} I've added |
Really like the idea of a separate |
# By Adam Wathan (307) and others # Via GitHub (131) and Adam Wathan (10) * master: (488 commits) Update changelog Using CSS Logical Properties in space and divide layout utilities (#1883) Update changelog Ensure changes to withOptions plugins trigger rebuilds Update changelog Update postcss-nested to version 5.0.1 (#2595) Update postcss-js to version 3.0.1 (#2594) Remove eslint-config-postcss Update autoprefixer Bust module cache Trigger CI Upgrade postcss: 7.0.32 → 8.1.1 (major) (#2593) Update changelog Remove word-wrap fallback for IE11 Prettier likes parens a lot now Upgrade @fullhuman/postcss-purgecss: 2.3.0 → 3.0.0 (major) (#2589) Don't warn about future flags Revert "Automatically add `featureFlags.future` flags to the configuration files whenever the `init` command is ran (#2379)" Update changelog Add SFMono-Regular to default mono font stack ...
@adamwathan Done, thanks! |
Awesome thanks! |
When transitioning a
transform
,translate3d
gives better performance (i.e. a smoother transition) thantranslateX
andtranslateY
.