How to make an atom like animation using CSS3 animations?

后端 未结 3 1034
遥遥无期
遥遥无期 2021-02-01 20:02

I\'ve being trying this since 3-4 days but am not able to get how do I make this animation, not even sure whether is possible to make one like this using only CSS3?

3条回答
  •  不知归路
    2021-02-01 20:43

    Found this online.

    It utilizes the transform-style: preserve-3d property and rotates the electrons on the x, y and z axis to achieve this 3D effect.

    HTML Structure

    CSS

    .orbit { 
        -webkit-transform-style: preserve-3d; 
        -webkit-transform: rotateX(80deg) rotateY(20deg);
    }
    
    #atom .orbit:nth-child(2) { 
       -webkit-transform: rotateX(80deg) rotateY(70deg)
    }
    #atom .orbit:nth-child(3) { 
       -webkit-transform: rotateX(80deg) rotateY(-20deg)
    }
    #atom .orbit:nth-child(4) { 
       -webkit-transform: rotateX(80deg) rotateY(-50deg)
    }
    
    .path { 
        -webkit-transform-style: preserve-3d;
        -webkit-animation-name: pathRotate;
        -webkit-animation-duration: 2s;
        -webkit-animation-iteration-count: infinite;
        -webkit-animation-timing-function: linear; 
    }
    
    .electron { 
        -webkit-animation-name: electronFix; 
        -webkit-animation-duration: 2s; 
        -webkit-animation-iteration-count: infinite; 
        -webkit-animation-timing-function: linear;  
    }
    
    @-webkit-keyframes pathRotate { 
        from { 
           -webkit-transform: rotateZ(0deg);
        } to { 
           -webkit-transform: rotateZ(360deg); 
        } 
    }
    
    @-webkit-keyframes electronFix { 
        from { 
           -webkit-transform: rotateX(90deg) rotateY(0deg); 
        } to { 
           -webkit-transform: rotateX(90deg) rotateY(-360deg); 
        } 
    }
    

    Fiddle

    Blog Post

提交回复
热议问题