Skip to content
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-transforms] How to animate image to Topright of viewport #11484

Open
FirstByteFirst opened this issue Jan 11, 2025 · 0 comments
Open

[css-transforms] How to animate image to Topright of viewport #11484

FirstByteFirst opened this issue Jan 11, 2025 · 0 comments
Labels
css-transforms-1 Current Work

Comments

@FirstByteFirst
Copy link

I understand CSS-transforms can not produce every animation I would like, but how about the most simple animation I can think of?

Suppose there is a small image shown in the viewport. Create an animation that moves the image to Topright of the viewport.

I would expect that this animation would do the job:

@Keyframes moveTopRight {
from {transform: translateXY(0,0);}
to {transform: translateXY(100vw,0vh);}
}

But they do not because vw and vh are relative values also. The only solution I see is to get rid of the vw and vh and translate them to px. This is very clumsy.

A common "solution" for an animation to move the image out of the viewport from the left is this:

@Keyframes VanishRight {
from {transform: translateX(0);}
to {transform: translateX(2000px);}
}

Now let's hope nobody has a viewport more then 2000px wide.. Clumsy again. It would be great if the browser could give some help with constructions like translateX(calc(100vw - ox)) where 'ox' (or how you want to name it) would be the x-position of the image. Or calc(100vw - left) (besides left also right, top, bottom, width and height)

Maybe I overlooked something in the documentation but any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-transforms-1 Current Work
Projects
None yet
Development

No branches or pull requests

2 participants