how rotate an image around on oval shape image in css3 animation?

前端 未结 1 829
礼貌的吻别
礼貌的吻别 2020-12-21 06:00

am a beginner in css3 animations.i have one task like,a pen image is rotate around on oval shape image.as much as i can i tried the following code is used on my task.can y

相关标签:
1条回答
  • 2020-12-21 06:48

    What is easily done in CSS is to rotate something. To make it go around in an oval shape, you can deform the place where you are doing the rotation. And, to make the object that you are rotating keep the aspect ratio, you need to undo the previous transforms.

    The HTML:

    <div class="deform">
    <div class="rotate">
    <div class="counterrotate">
    <div class="inner">A
    </div>
    </div>
    </div>
    </div>
    

    and the CSS

    .deform  {
    width: 200px;
    height: 200px;
    -webkit-transform: scaleX(3);
    background-color: lightblue;
    left: 270px;
    position: absolute;
    top: 50px;
    border-radius: 50%;
    }
    
    .rotate {
    width: 100%;
    height: 100%;
    -webkit-animation: circle 10s infinite linear;    
    -webkit-transform-origin: 50% 50%;
    }
    
    .counterrotate {
    width: 50px;
    height: 50px;
    -webkit-animation: ccircle 10s infinite linear;    
    }
    
    .inner {
    width: 50px;
    height: 50px;
    position: absolute;
    left: 0px;
    top: 0px;
    background-color: red;
    display: block;
    -webkit-transform: scaleX(0.33);
    }
    
    @-webkit-keyframes circle {
    from {-webkit-transform: rotateZ(0deg)}
    to {-webkit-transform: rotateZ(360deg)}
    }
    
    @-webkit-keyframes ccircle {
    from {-webkit-transform: rotateZ(360deg)}
    to {-webkit-transform: rotateZ(0deg)}
    }
    

    demo

    0 讨论(0)
提交回复
热议问题