Home Web Front-end CSS Tutorial Use CSS3 properties to implement the animation example code of the villain

Use CSS3 properties to implement the animation example code of the villain

Mar 28, 2017 pm 05:32 PM
css3

Use various CSS3 properties to implement animations with musical figures, without using JS code at all:

Note: Chrome browser has the best effect, and the final effect is a static image:

Use CSS3 properties to implement the animation example code of the villain

HTML code is as follows:


    
    
    练习一个小人的动画
     
    
        
    
    
    
    
        
        
            
        
            
            I
            ♥
            Y
            O
            U
            
            
            
        
        
        
        
            
            
            
            
            
                
                
                
            
            
            
                
                
                
                
                    
                
                
                
                    
                    
                
                
                
                    
                    
                
                
                
            
        
        
        
        ♫
        ♪
Copy after login

CSS code is as follows:


/* CSS Document */body,html{
    width:100%;
    height:100%;
    margin:0;
    display:table;
    text-align:center;
}.music1{
    display:none;
}.warp{ 
    margin-top:100px; 
    vertical-align:middle; 
    position:relative;
}.backgroud_circle{
    width:400px;
    height:400px;
    border-radius:100%;
    background:#6699FF;
    margin:0 auto;
    overflow:hidden;
    -webkit-mask-image: -webkit-radial-gradient(#BADA55, #BADA55);
    -moz-mask-image: -webkit-radial-gradient(#BADA55, #BADA55);
      -o-mask-image: -webkit-radial-gradient(#BADA55, #BADA55);
      -ms-mask-image: -webkit-radial-gradient(#BADA55, #BADA55);    /*执行动画*/
    animation:grow 0.7s ease;
    -webkit-animation:grow 0.7s ease;
    transform-origin:center;
}/*身体body*/.body{
    width:285px;
    height:400px;
    margin:0 auto;
    background:#333333;
    position:relative;
    top:100px;
    border-radius:100px;    /*执行动画*/
    -webkit-animation:body-enter 0.7s 0.2s 1 ease;
    animation:body-enter 0.7s 0.2s 1 ease;    /*-webkit-animation-fill-mode:forwards;
    animation-fill-mode:forwards;*/}/*头部head*/.head{
    width:196px;
    height:260px;
    border-radius:50px;
    background:#ffe4be;
    position:absolute;
    top:50%;
    left:50%;
    margin-top:-210px;
    margin-left:-98px;    /*动画执行*/
    animation:grow 0.7s 0.5s ease;
    -webkit-animation:grow 0.7s 0.5s ease;
    transform-origin:bottom;
}/*头发*/.hair-main{
    width:220px;
    height:0px;
    background:#FF9966;
    border-radius:54px 54px 0px 0px;
    animation:hair-main 0.7s 0.9s ease;
    -webkit-animation:hair-main 0.7s 0.9s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    position:relative;
    margin-left:-12px;
    margin-top:-10px;
    z-index:2;
}/*鬓角*/.sideburn{
    width:8px;
    height:25px;
    background:#FF9966;
    opacity:0;
    bottom:-25px;
    position:absolute;
    animation:sideburn-main 0.7s 1s ease;
    -webkit-animation:sideburn-main 0.7s 1s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
}.sideburn#left{
    left:12px;
}.sideburn#right{
    right:12px;
}/*耳朵*/.ear{
    width:24px;
    height:35px;
    position:absolute;
    background:#ffe4be;
    top:116px;
    border-radius:12px;
    animation:grow 0.7s 1.3s ease;
    -webkit-animation:grow 0.7s 1.3s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    transform:scale(0);
    -webkit-transform:scale(0);
}.ear#left{
    left:-12px;
}.ear#right{
    right:-12px;
}/*脸部*/.face{
    width:180px;
    height:0px;
    border-radius:48px;
    background:#ffe4be;
    position:absolute;
    top:40px;
    left:8px;
    animation:hair-main 0.7s 0.5s linear;
    -webkit-animation:hair-main 0.7s 0.5s linear;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    z-index:3;
}/*鼻子*/.nose{
    width:20px;
    height:45px;
    opacity:1;
    border-top-left-radius:20px;
    background:#ffe4be;
    position:absolute;
    top:80px;
    left:50%;
    margin-left:-20px;
    animation:shadow-main 0.7s 3s ease;
      animation-fill-mode: forwards;
      -webkit-animation:shadow-main 0.7s 3s ease;
      -webkit-animation-fill-mode: forwards;
      opacity:0;
     z-index:5;
}/*形成鼻子的阴影*/.shadow-main{
    width:98px;
    height:260px;
    position:absolute;
    bottom:-84px;
    left:-8px;
    z-index:4;
    overflow:hidden;
}.shadow{
    width:98px;
    height:260px;
    border-radius:50px;
    background:rgba(149,36,0,0.1);
    position:absolute;
    opacity:0;
    z-index:4;
    animation:shadow-main 1s 2.8s ease;
    -webkit-animation:shadow-main 1s 2.8s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
}/*眼睛阴影*/.eye-shadow{
    width:30px;
    height:15px;
    border-radius:0 0 15px 15px;
    background:rgba(149,36,0,0.1);
    position:absolute;
    top:70px;
    animation:grow 0.7s 2s ease;
    -webkit-animation:grow 0.7s 2s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    transform:scale(0);
    -webkit-transform:scale(0);
}.eye-shadow#left{
    left:35px;
    z-index:5;
}.eye-shadow#right{
    right:35px;
}/*眼眉*/.eyebrow{
    width:40px;
    height:10px;
    background:#FF9966;
    position:absolute;
    top:-35px;
    left:50%;
    opacity:0;
    margin-left:-20px;
    -webkit-backface-visibility:hidden;/*设定元素的背面是否可见*/}.eyebrow#left{
    animation:eyebrow-left 0.7s 2.2s ease;
    -webkit-animation:eyebrow-left 0.7s 2.2s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
}.eyebrow#right{
    animation:eyebrow-right 0.7s 2.2s ease, eyebrow-right-raise 2s 6.6s infinite alternate ease-in-out;
    -webkit-animation:eyebrow-right 0.7s 2.2s ease, eyebrow-right-raise 2s 6.6s infinite alternate ease-in-out;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
}/*两只蓝色眼睛*/.eye{
    width:20px;
    height:28px;
    border-radius:10px;
    background:#334C68;
    position:absolute;
    top:-18px;
    left:50%;
    margin-left:-10px;
    animation:grow 0.7s 2.2s ease;
    -webkit-animation:grow 0.7s 2.2s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    transform:scale(0);
    -webkit-transform:scale(0);
    transform-origin:bottom;
    -webkit-transform-origin:bottom;
}/*嘴巴*/.mouse{
    width:66px;
    height:33px;
    background:#FFFFFF;
    border-radius:0 0 33px 33px;
    position:absolute;
    left:50%;
    top:150px;
    margin-left:-33px;
    animation:grow 0.7s 2.6s ease;
    -webkit-animation:grow 0.7s 2.6s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    transform:scale(0);
    -webkit-transform:scale(0);
}/*背景高亮light阴影*/.tight-light{
    width:400px;
    height:600px;
    background:#ffffff;
    opacity:0;
    position:absolute;
    right:15%;
    animation:tight-light 1s 2.8s ease;
    -webkit-animation:tight-light 1s 2.8s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    transform:translate(200px,0px);
    -webkit-transform:translate(200px,0px);
}/*背景高亮dark阴影*/.tight-dark{
    width:400px;
    height:600px;
    background:#000000;
    opacity:0;
    position:absolute;
    left:10%;
    top:35px;
    animation:tight-dark 1s 2.8s ease;
    -webkit-animation:tight-dark 1s 2.8s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
    transform:translate(-200px,0px);
    -webkit-transform:translate(-200px,0px);
    z-index:6;
}/*外边黄色圈*/.border_circle{
    width:399px;
    height:399px;
    border-radius:50%;
    border:10px solid #ff8345;
    position:absolute;
    top:50%;
    left:50%;
    margin-left:-220px;
    margin-top:-220px;
    transform:scale(0);
    -webkit-transform:scale(0);
    transform-origin:center;
    -webkit-transform-origin:center;
}/*外边黄色圈one*/.border_circle#one{
    animation:border_circle 1s 3.1s ease;
    -webkit-animation:border_circle 1s 3.1s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
}/*外边黄色圈two*/.border_circle#two{
    animation:border_circle 1s 3.3s ease;
    -webkit-animation:border_circle 1s 3.3s ease;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
}/*I YOU*/.backgroud_circle  .shirt-text{
    font-family:"微软雅黑",sans-serif;
    font-size:50px;
    font-weight:700;
    color:#FFFFFF;
    position:relative;
    top:180px;
    display:inline-block;
    -webkit-text-stroke:2px;
    text-stroke:2px;
    opacity:0;
    -webkit-transform:translate(0px,100px);
    transform:translate(0px,100px);
    animation-fill-mode:forwards !important;
    -webkit-animation-fill-mode:forwards !important;
    z-index:5;
}.backgroud_circle .shirt-text:nth-of-type(1){
    animation:shirt-text 0.7s 3.3s ease;
    -webkit-animation:shirt-text 0.7s 3.3s ease;
}.backgroud_circle .shirt-text:nth-of-type(2){
    color:#FF0000;
    animation:shirt-text 0.7s 3.4s ease, heart 2s 4s infinite ease-in-out;
    -webkit-animation:shirt-text 0.7s 3.4s ease, heart 2s 4s infinite ease-in-out;
}.backgroud_circle .shirt-text:nth-of-type(3){
    animation:shirt-text 0.7s 3.5s ease;
    -webkit-animation:shirt-text 0.7s 3.5s ease;
}.backgroud_circle .shirt-text:nth-of-type(4){
    animation:shirt-text 0.7s 3.6s ease;
    -webkit-animation:shirt-text 0.7s 3.6s ease;
}.backgroud_circle .shirt-text:nth-of-type(5){
    animation:shirt-text 0.7s 3.7s ease;
    -webkit-animation:shirt-text 0.7s 3.7s ease;
}/*音符*/.music{
    position: absolute;
    font-size: 150px;
    color: #FCB040;
    width: 1px;
    left: 50%;
    opacity: 0;
}.music#one{
    margin-left:-250px;
    top:50%;
    animation: note 2s 3.5s infinite ease;
    animation-fill-mode: forwards;
    -webkit-animation: note 2s 3.5s infinite ease;
    -webkit-animation-fill-mode: forwards;
}.music#two{
  margin-left: 150px;
  top: 30%;
  animation: note 2s 4.3s infinite ease;
  animation-fill-mode: forwards;
  -webkit-animation: note 2s 4.3s infinite ease;
  -webkit-animation-fill-mode: forwards;
}/*背景圆圈的动画事件:由中心向外扩张*/@-webkit-keyframes grow{
    0%{ -webkit-transform:scale(0); transform:scale(0);}
    60%{ -webkit-transform:scale(1.15); transform:scale(1.15);}
    80%{ -webkit-transform:scale(0.95); transform:scale(0.95);}
    100%{ -webkit-transform:scale(1); transform:scale(1);}}
@keyframes grow{
    0%{ -webkit-transform:scale(0); transform:scale(0);}
    60%{ -webkit-transform:scale(1.15); transform:scale(1.15);}
    80%{ -webkit-transform:scale(0.95); transform:scale(0.95);}
    100%{ -webkit-transform:scale(1); transform:scale(1);}}/*身体进入样式:由底部向上先变大再恢复正常*/@-webkit-keyframes body-enter{
    0%{-webkit-transform:translateY(200px);}
    60%{-webkit-transform:translateY(-20px);}
    80%{-webkit-transform:translateY(30px);}
    100%{-webkit-transform:translateY(0);}}
@keyframes body-enter{
    0%{-webkit-transform:translateY(200px);}
    60%{-webkit-transform:translateY(-20px);}
    80%{-webkit-transform:translateY(30px);}
    100%{-webkit-transform:translateY(0);}}/*头发动画:*/@-webkit-keyframes hair-main{
    0%{height:0px; -webkit-transform:translateY(137px); transform:translateY(137px);}
    100%{height:137px; -webkit-transform:translateY(0); transform:translateY(0);}}
@keyframes hair-main{
    0%{height:0px; -webkit-transform:translateY(137px); transform:translateY(137px);}
    100%{height:137px; -webkit-transform:translateY(0); transform:translateY(0);}}/*鬓角动画*/@-webkit-keyframes sideburn-main{
    0%{opacity:0; -webkit-transform:translateY(-25px); transform:translateY(-25px);}
    100%{opacity:1; -webkit-transform:translateY(0); transform:translateY(0);}}
@keyframes sideburn-main{
    0%{opacity:0; -webkit-transform:translateY(-25px); transform:translateY(-25px);}
    100%{opacity:1; -webkit-transform:translateY(0); transform:translateY(0);}}/*鼻子阴影动画:*/@-webkit-keyframes shadow-main{
    0%{ opacity:0; -webkit-transform:translate(98px,0px); transform:translate(98px,0px);}
    50%{ opacity:0;}
    100%{ opacity:1; -webkit-transform:translate(0px,0px); transform:translate(0px,0px);}}
@keyframes shadow-main{
    0%{ opacity:0; -webkit-transform:translate(98px,0px); transform:translate(98px,0px);}
    50%{ opacity:0;}
    100%{ opacity:1; -webkit-transform:translate(0px,0px); transform:translate(0px,0px);}}/*左眼眉动画*/@-webkit-keyframes eyebrow-left{
    0%{opacity:0; -webkit-transform:translateY(-25px); transform:translateY(-25px);}
    70%{opacity:1; -webkit-transform:translateY(5px); transform:translateY(5px);}
    100%{opacity:1; -webkit-transform:translateY(0); transform:translateY(0);}}
@keyframes eyebrow-left{
    0%{opacity:0; -webkit-transform:translateY(-25px); transform:translateY(-25px);}
    70%{opacity:1; -webkit-transform:translateY(5px); transform:translateY(5px);}
    100%{opacity:1; -webkit-transform:translateY(0); transform:translateY(0);}}/*右眼眉动画*/@-webkit-keyframes eyebrow-right{
    0%{opacity:0; -webkit-transform:translateY(-25px); transform:translateY(-25px);}
    70%{opacity:1; -webkit-transform:translateY(5px); transform:translateY(5px);}
    100%{opacity:1; -webkit-transform:rotate(9deg) translateY(0); transform:rotate(9deg) translateY(0);}}
@keyframes eyebrow-right{
    0%{opacity:0; -webkit-transform:translateY(-25px); transform:translateY(-25px);}
    70%{opacity:1; -webkit-transform:translateY(5px); transform:translateY(5px);}
    100%{opacity:1; -webkit-transform:rotate(9deg) translateY(0); transform:rotate(9deg) translateY(0);}}/*眉毛上升动画*/@-webkit-keyframes eyebrow-right-raise{
    0%{top:-35px;}
    70%{top:-35px;}
    100%{top:-45px;}}
@keyframes eyebrow-right-raise{
    0%{top:-35px;}
    70%{top:-35px;}
    100%{top:-45px;}}/*背景高亮light动画*/@-webkit-keyframes tight-light{
    0%{opacity:0; -webkit-transform:translate(200px,0px); transform:translate(200px,0px);}
    100%{opacity:0.2; -webkit-transform:rotate(45deg) translate(0px,0px); transform:rotate(45deg) translate(0px,0px);}}
@keyframes tight-light{
    0%{opacity:0; -webkit-transform:translate(200px,0px); transform:translate(200px,0px);}
    100%{opacity:0.2; -webkit-transform:rotate(45deg) translate(0px,0px); transform:rotate(45deg) translate(0px,0px);}}/*背景高亮dark动画*/@-webkit-keyframes tight-dark{
    0%{opacity:0; -webkit-transform:translate(-200px,0px); transform:translate(-200px,0px);}
    100%{opacity:0.2; -webkit-transform:rotate(-45deg) translate(0px,0px); transform:rotate(-45deg) translate(0px,0px);}}
@keyframes tight-dark{
    0%{opacity:0; -webkit-transform:translate(-200px,0px); transform:translate(-200px,0px);}
    100%{opacity:0.2; -webkit-transform:rotate(-45deg) translate(0px,0px); transform:rotate(-45deg) translate(0px,0px);}}/*外面黄色圈动画*/@-webkit-keyframes border_circle{
    0%{ border-width:20px; transform:scale(0); -webkit-transform:scale(0);}
    40%{ border-width:20px; transform:scale(1); -webkit-transform:scale(1); margin-left:-220px; margin-top:-220px;}
    100%{ border-width:0px; transform:scale(1.5); -webkit-transform:scale(1.5); border-style:double; margin-left:-200px; margin-top:-200px;}}
@keyframes border_circle{
    0%{ border-width:20px; transform:scale(0); -webkit-transform:scale(0);}
    40%{ border-width:20px; transform:scale(1); -webkit-transform:scale(1); margin-left:-220px; margin-top:-220px;}
    100%{ border-width:0px; transform:scale(1.5); -webkit-transform:scale(1.5); border-style:double; margin-left:-200px; margin-top:-200px;}}/*文字*/@-webkit-keyframes shirt-text{
    0%{opacity:0; -webkit-transform:translate(0px, 80px); transform:translate(0px, 80px);}
    60%{opacity:1; -webkit-transform:translate(0px, -50px); transform:translate(0px, -50px);}
    80%{opacity:1; -webkit-transform:translate(0px, 140px); transform:translate(0px, 140px);}
    100%{opacity:1; -webkit-transform:translate(0px, 100px); transform:translate(0px, 100px);}}
@keyframes shirt-text{
    0%{opacity:0; -webkit-transform:translate(0px, 80px); transform:translate(0px, 80px);}
    60%{opacity:1; -webkit-transform:translate(0px, -50px); transform:translate(0px, -50px);}
    80%{opacity:1; -webkit-transform:translate(0px, 140px); transform:translate(0px, 140px);}
    100%{opacity:1; -webkit-transform:translate(0px, 100px); transform:translate(0px, 100px);}}
@-webkit-keyframes heart{
    0%{ }
    30%{color:#00FF99;}
    70%{color:#FFFF00;}
    100%{}}
@keyframes heart{
    0%{ }
    30%{color:#00FF99;}
    70%{color:#FFFF00;}
    100%{}}/*音符*/@-webkit-keyframes note{
    0% {
      opacity: 0;
      -webkit-transform: translate(0px,50px);
      transform: translate(0px,50px);
    }
    30% {
      -webkit-transform:rotate(12deg) translate(-30px,0px);
      transform:rotate(12deg) translate(-30px,0px);
    }
    45% {
      opacity: 1;
    }  
    60% {
      -webkit-transform: rotate(-12deg) translate(30px,-100px);
      transform:rotate(-12deg) translate(30px,-100px);
    }
    100% {
      opacity: 0;
      -webkit-transform:rotate(0deg) translate(0px,-200px);
      transform:rotate(0deg) translate(0px,-200px);
    }}
@keyframes note{
    0% {
      opacity: 0;
      -webkit-transform: translate(0px,50px);
      transform: translate(0px,50px);
    }
    30% {
      -webkit-transform:rotate(12deg) translate(-30px,0px);
      transform:rotate(12deg) translate(-30px,0px);
    }
    45% {
      opacity: 1;
    }  
    60% {
      -webkit-transform: rotate(-12deg) translate(30px,-100px);
      transform:rotate(-12deg) translate(30px,-100px);
    }
    100% {
      opacity: 0;
      -webkit-transform:rotate(0deg) translate(0px,-200px);
      transform:rotate(0deg) translate(0px,-200px);
    }}
Copy after login

The above is the detailed content of Use CSS3 properties to implement the animation example code of the villain. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to achieve wave effect with pure CSS3? (code example) How to achieve wave effect with pure CSS3? (code example) Jun 28, 2022 pm 01:39 PM

How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

Use CSS skillfully to realize various strange-shaped buttons (with code) Use CSS skillfully to realize various strange-shaped buttons (with code) Jul 19, 2022 am 11:28 AM

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

How to hide elements in css without taking up space How to hide elements in css without taking up space Jun 01, 2022 pm 07:15 PM

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

How to enlarge the image by clicking the mouse in css3 How to enlarge the image by clicking the mouse in css3 Apr 25, 2022 pm 04:52 PM

Implementation method: 1. Use the ":active" selector to select the state of the mouse click on the picture; 2. Use the transform attribute and scale() function to achieve the picture magnification effect, the syntax "img:active {transform: scale(x-axis magnification, y Axis magnification);}".

It turns out that text carousel and image carousel can also be realized using pure CSS! It turns out that text carousel and image carousel can also be realized using pure CSS! Jun 10, 2022 pm 01:00 PM

How to create text carousel and image carousel? The first thing everyone thinks of is whether to use js. In fact, text carousel and image carousel can also be realized using pure CSS. Let’s take a look at the implementation method. I hope it will be helpful to everyone!

How to set animation rotation speed in css3 How to set animation rotation speed in css3 Apr 28, 2022 pm 04:32 PM

In CSS3, you can use the "animation-timing-function" attribute to set the animation rotation speed. This attribute is used to specify how the animation will complete a cycle and set the speed curve of the animation. The syntax is "element {animation-timing-function: speed attribute value;}".

Does css3 animation effect have deformation? Does css3 animation effect have deformation? Apr 28, 2022 pm 02:20 PM

The animation effect in css3 has deformation; you can use "animation: animation attribute @keyframes ..{..{transform: transformation attribute}}" to achieve deformation animation effect. The animation attribute is used to set the animation style, and the transform attribute is used to set the deformation style. .

See all articles