3

Is there a way to customize transforms and transitions in CSS? For example, in this Jsfiddle, I'd like to for the first 2 seconds, transform 110 degrees, then for 4 seconds, transform 200 degrees.

http://jsfiddle.net/jzhang172/b5zun436/

.box {
    border-style: solid;
    border-width: 1px;
    display: block;
    width: 100px;
    height: 100px;
    background-color: #0000FF;
    -webkit-transition: width 2s, height 2s, background-color 2s, -webkit-transform 2s;
    transition: width 2s, height 2s, background-color 2s, transform 2s;
}

.box:hover {
    background-color: #FFCCCC;
    width: 200px;
    height: 200px;
    -webkit-transform: rotate(110deg);
    transform: rotate(110deg);
}
<p>CSS question: IS there a way to customize the transform? (i.e., transform box to 110 deg, duration 2 seconds and then transform box another 180 degrees, duration 5 seconds. </p>
    <div class="box"></div>

1
  • Why not use a CSS animation? Commented Oct 3, 2015 at 16:42

1 Answer 1

4

You need to use key-frame animation for this, that's why it is called as key frame animation, where you define it frame by frame.

@keyframes myAnimation {
    0%    { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
    33.3% { -webkit-transform: rotate(110deg); transform: rotate(110deg); }
    100%  { -webkit-transform: rotate(200deg); transform: rotate(200deg); }
}
Sign up to request clarification or add additional context in comments.

2 Comments

@Snorlax Hope this helped. Wow, I am surprised you didn't know about this. :)
@ManojKumar No no, no bad words. :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.