CSS3 Multiple transforms

2019-02-23 19:23发布

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.

标签: html5 css3 3d
2条回答
狗以群分
2楼-- · 2019-02-23 20:18

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/

查看更多
看我几分像从前
3楼-- · 2019-02-23 20:20

I have not tested this, but what about

@-webkit-keyframes spin2 {
    from {
        -webkit-transform: rotateX(135deg);
        -webkit-transform: rotateY(135deg);
    }
    to   {
        -webkit-transform: rotateX(855deg);
        -webkit-transform: rotateY(855deg);
    }
}
查看更多
登录 后发表回答