4

I have a css3 animation, im using the code below to rotate a cube on the X-axis.

@-webkit-keyframes spin2 {
from { -webkit-transform: rotateX(135deg); }
to   { -webkit-transform: rotateX(855deg); }
}

I need to do the code below at the same time as the code above so the cube can rotate on both axis simultaneously.

@-webkit-keyframes spin2 {
from { -webkit-transform: rotateY(135deg); }
to   { -webkit-transform: rotateY(855deg); }
}

Adding the code for the x and y rotation doesn't work, I need to combine these. Is this possible. This is my first time working with css3. Any help would be appreciated.

2 Answers 2

9

This should work:

    .yourElement {
        -webkit-animation:spin 4s infinite;
    }
    @-webkit-keyframes spin {
      from {
        -webkit-transform: rotateX(135deg) rotateY(135deg);
      }
      to {
        -webkit-transform: rotateX(855deg) rotateY(855deg);
      }
    }

Sample: http://jsfiddle.net/KRYRk/1/

Sign up to request clarification or add additional context in comments.

4 Comments

@Charl - in what browser are you looking at it? Works for me in Chrome and Safari.
Im using Chrome, below is a link to the cube, its rotating at the moment but its not meant to. With the code you supplied it doesnt seem to work but the starting and ending points dont ever seem to match up so a seamless loop isnt shown. Your code: phoenixdigital.co.za/test/cube/imagecube/new Old code(not meant to work, has a syntax error) phoenixdigital.co.za/test/cube/imagecube
@Charl - I just used your degrees settings - you have to edit it to fit what you want - the code i provided works - to make it smooth and work like you want it's up to you. Do your math - I provided you the code sample on jsfiddle - play with it in there.
Keep in mind Android doesn't support more than one transform simultaneously and using rotate3d can combine these into one single transform command. Just an FYI, not saying you needed to know, but it's nice to know. :)
-3

You can use several transform functions in the transform property by separating them with a space:

@-webkit-keyframes spin2 {
    from {
        -webkit-transform: rotateX(135deg) rotateY(135deg);
    }
    to   {
        -webkit-transform: rotateX(855deg) rotateY(855deg);
    }
}

3 Comments

Thanks for your reply Connum. Ive just tested this and it doesnt seem to work. It just does the first transform and ignores the second.
Does this page help you? css-tricks.com/snippets/css/webkit-keyframe-animation-syntax As far as I understand, you could define two animations and then apply them comma-seperated via -webkit-animation:.
Ive gone though this page and I cant make much sense out of it, from what I understand I need to Combine multiple transforms and animations but Im not sure. Its my first time using CSS3.

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.