Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 animation scale

Tags:

css

animation

I'm trying to animate a div so that when the page load it has scale(0,0) and animates to scale(1,1). The problem I have is that once the animation takes effect the div scales to 0 again. What I want is the div to animate to scale(1,1) and staying like that. Here's my CSS code

@-moz-keyframes bumpin {
    0% { -moz-transform: scale(0,0); }
    100%   { -moz-transform: scale(1,1); }
}

.landing .board {
    -moz-transform: scale(0,0);
    -moz-transform-origin: 50% 50%;
}

.landing .board {
    -moz-animation-name: bumpin;
    -moz-animation-duration: 1s;
    -moz-animation-timing-function: ease;
    -moz-animation-delay: 0s;
    -moz-animation-iteration-count: 1;
    -moz-animation-direction: normal;
}

What am I doing wrong?

Thanks in advance
Mauro

like image 771
Mauro74 Avatar asked Feb 08 '12 15:02

Mauro74


People also ask

What is scale () in CSS?

The scale() CSS function defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales. Its result is a <transform-function> data type.

How do you make a scale smooth in CSS?

Passing a single argument to the scale() function changes the size of an element uniformly, scaling both the height and width by the same amount.


2 Answers

You're looking for animation-fill-mode:forwards which applies the last keyframe of the nimation to the element when the animation is done. https://developer.mozilla.org/en/CSS/animation-fill-mode

-moz-animation-fill-mode: forwards
like image 105
rgthree Avatar answered Nov 16 '22 02:11

rgthree


Another way of doing this: If all you want to do is animate an element to scale, you don't need to use keyframes. transitions will suffice.

.landing-board {
  -moz-transition: all 1s ease;
  /* all other css properties */
}
.landing-board.animated {
  -moz-transform: scale(1.1);
}

And very little javascript to add the related class to your element: (Here i'm using jquery but it could be done in any other framework or pure javascript)

$(window).load(function() {
  $('.landing-board').addClass('animated');
});
like image 22
keune Avatar answered Nov 16 '22 02:11

keune