Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS translateY()

I am moving some element from (browser height + element height)px towards the top of the browser at -50px of the browser using CSS keyframes and that works but the problem is it's lagging and I am well aware that using translateY would resolve this issue.

Now assume I have a CSS as follows.

.bubble
{
    -webkit-transition: -webkit-transform 1s ease-in-out;
}

.bubble.move
{
    -webkit-transform: translateY(-50px);
}

As the element is below the browser screen (browser height + element height)px and I want it to move at the top of the screen at -50px, that doesn't work. It just moves the element from its current position to the -50px of that current position which is not intended. How can I ask transitions to go at -50px of the browser and not he element?

like image 338
Umair A. Avatar asked Apr 10 '26 05:04

Umair A.


1 Answers

Translate isn't what you're looking for. You want to position the element absolutely and put the transition on the top property. Something like:

.bubble {
  position:absolute;
  top:100%;
  transition:top 1s ease-in-out;
}
.bubble.move {
  top:50px;
}

Only bad part about this approach is that the body will need to be the relative parent of the .bubble. I left out vendor prefixes because I hate them.

like image 115
mike.pj Avatar answered Apr 11 '26 18:04

mike.pj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!