<bdo id="z6w4c"></bdo>\r\n    \r\n        我是demo    <\/div><\/body><\/pre>
.demo{\r\n    width: 120px;\r\n    height: 120px;\r\n    margin: 100px auto;\r\n    background: url(img\/demo.jpg) no-repeat;\r\n}<\/pre>

An ordinary DIV comes out, as shown on the right:\"Learn<\/p>

Then we make it move<\/p>

First write a method, which describes how this picture should move<\/p>

@keyframes run_animation{      \r\n    from {\r\n        transform: rotatez(0deg);\r\n    }\r\n    to {\r\n        transform: rotatez(360deg);\r\n    }\r\n}<\/pre>

This animation_run is the name of this method. You need to associate the name to the relevant element later. <\/p>

from describes the starting state of the animation, and to is the end state of the animation. <\/p>

So this method is to rotate an element 360 degrees in a clockwise direction, which is very simple. <\/p>

from to often cannot meet our daily development needs, so there is also this way of writing <\/p>

@keyframes run_animation{\r\n    0%{
     transform:rotatex(0deg);
   }\r\n    16%{\r\n        transform: rotatey(-90deg);\r\n    }\r\n    33%{\r\n        transform: rotatey(-90deg) rotatez(135deg);\r\n    }\r\n    50%{\r\n        transform: rotatey(225deg) rotatez(135deg);\r\n    }\r\n    66%{\r\n        transform: rotatey(135deg) rotatex(135deg);\r\n    }\r\n    83%{\r\n        transform: rotatex(135deg);\r\n    }
  100%{
     transform: rotatex(0deg);
  }\r\n}<\/pre>

This description allows the animation to have richer and cooler actions. The dynamics of the element at each stage are described by percentages. 0% is the from mentioned above, and 100% is to. In fact, this is very simple, right~<\/p>

The animation is so easy to write. Next we attach the animation to our image. <\/p>

.demo{\r\n    width: 120px;\r\n    height: 120px;\r\n    margin: 100px auto;\r\n    animation: run_animation 12s linear infinite; \/*關(guān)聯(lián)動(dòng)畫名稱,定義動(dòng)畫時(shí)長,動(dòng)畫播放速度曲線,播放次數(shù)*\/\r\n    background: url(img\/demo.jpg) no-repeat 100%;\r\n}<\/pre>

With such a simple code, the picture can move according to the method we defined. <\/p>

If you find that the animation is not moving now, it may be one of the following reasons: <\/p>

1. The animation name does not match the name defined by @keyframes; <\/p>

2. The animation playback duration is not defined, and the default is 0S, that is, no Play animation. The above code definition is 12S; <\/p>

3. Run this code in IE9 and below browsers, IE9 and below does not support CSS3 animation; <\/p>

4. The animation method is incorrectly defined, and the style is the same in each stage of the method definition. Like this <\/p>

@keyframes run_animation{\r\n    0%{\r\n        transform: rotatez(90deg);\r\n    }\r\n    50%{\r\n        transform: rotatez(90deg);\r\n    }\r\n   100%{\r\n        transform: rotatez(90deg);\r\n    }\r\n}<\/pre>

Okay, now the animation should be moving. Next, let’s talk about other options in animation: <\/p>\n

1. animation-iteration-count: The number of times the animation is played, write down how many times you want to play it. What I have used infinite times here is infinite<\/p>\n

2. animation-timing-function: animation speed curve. This speed curve is a bit complicated and involves a Bessel function. If you don’t want to explore Bezier in depth, just use the ready-made linear, ease, ease-in, ease-out, and ease-in-out. If you know Bezier, you can use cubic-bezier(n,n,n,n). This is more advanced and I think it is a powerful tool in the show-off world. <\/p>\n

3.animation-delay: Animation can be played with delay, and the parameters are also n S. Unlike animation-duration, animation-duration is the duration of animation playback. <\/p>\n

The above attributes can all be abbreviated to animation, just like my chestnut above. <\/p>\n

I won’t talk about the properties of reverse playback and pause. If necessary, you can go to http:\/\/www.w3school.com.cn\/css3\/css3_animation.asp or <\/p>\n

https:\/\/developer.mozilla.org\/ en-US\/docs\/Web\/CSS\/CSS_Animations\/Using_CSS_animation<\/p>\n

<\/p>"}

国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Web Front-end CSS Tutorial Learn CSS3 animation (animation)

Learn CSS3 animation (animation)

Oct 09, 2016 pm 04:12 PM

CSS3 has many advanced functions, such as 3D effects, animations, multiple columns, etc. Today I will write an article to record how to use CSS3 to write an animation.

I have to say something ugly first, IE9 and below versions do not support CSS3 animation (if you really want to implement it, you can consider using js, but the effect is not very good). Chrome and Safafi recommend adding the prefix -webkit- for forward compatibility with older versions.

Today I will simply make an animation.

First, simply draw a div and then add a background image.

<body>
    <div class="demo">
        我是demo    </div></body>
.demo{
    width: 120px;
    height: 120px;
    margin: 100px auto;
    background: url(img/demo.jpg) no-repeat;
}

An ordinary DIV comes out, as shown on the right:Learn CSS3 animation (animation)

Then we make it move

First write a method, which describes how this picture should move

@keyframes run_animation{      
    from {
        transform: rotatez(0deg);
    }
    to {
        transform: rotatez(360deg);
    }
}

This animation_run is the name of this method. You need to associate the name to the relevant element later.

from describes the starting state of the animation, and to is the end state of the animation.

So this method is to rotate an element 360 degrees in a clockwise direction, which is very simple.

from to often cannot meet our daily development needs, so there is also this way of writing

@keyframes run_animation{
    0%{<br>     transform:rotatex(0deg);<br>   }
    16%{
        transform: rotatey(-90deg);
    }
    33%{
        transform: rotatey(-90deg) rotatez(135deg);
    }
    50%{
        transform: rotatey(225deg) rotatez(135deg);
    }
    66%{
        transform: rotatey(135deg) rotatex(135deg);
    }
    83%{
        transform: rotatex(135deg);
    }<br>  100%{<br>     transform: rotatex(0deg);<br>  }
}

This description allows the animation to have richer and cooler actions. The dynamics of the element at each stage are described by percentages. 0% is the from mentioned above, and 100% is to. In fact, this is very simple, right~

The animation is so easy to write. Next we attach the animation to our image.

.demo{
    width: 120px;
    height: 120px;
    margin: 100px auto;
    animation: run_animation 12s linear infinite; /*關(guān)聯(lián)動(dòng)畫名稱,定義動(dòng)畫時(shí)長,動(dòng)畫播放速度曲線,播放次數(shù)*/
    background: url(img/demo.jpg) no-repeat 100%;
}

With such a simple code, the picture can move according to the method we defined.

If you find that the animation is not moving now, it may be one of the following reasons:

1. The animation name does not match the name defined by @keyframes;

2. The animation playback duration is not defined, and the default is 0S, that is, no Play animation. The above code definition is 12S;

3. Run this code in IE9 and below browsers, IE9 and below does not support CSS3 animation;

4. The animation method is incorrectly defined, and the style is the same in each stage of the method definition. Like this

@keyframes run_animation{
    0%{
        transform: rotatez(90deg);
    }
    50%{
        transform: rotatez(90deg);
    }
   100%{
        transform: rotatez(90deg);
    }
}

Okay, now the animation should be moving. Next, let’s talk about other options in animation:

1. animation-iteration-count: The number of times the animation is played, write down how many times you want to play it. What I have used infinite times here is infinite

2. animation-timing-function: animation speed curve. This speed curve is a bit complicated and involves a Bessel function. If you don’t want to explore Bezier in depth, just use the ready-made linear, ease, ease-in, ease-out, and ease-in-out. If you know Bezier, you can use cubic-bezier(n,n,n,n). This is more advanced and I think it is a powerful tool in the show-off world.

3.animation-delay: Animation can be played with delay, and the parameters are also n S. Unlike animation-duration, animation-duration is the duration of animation playback.

The above attributes can all be abbreviated to animation, just like my chestnut above.

I won’t talk about the properties of reverse playback and pause. If necessary, you can go to http://www.w3school.com.cn/css3/css3_animation.asp or

https://developer.mozilla.org/ en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animation

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

Hot Topics

PHP Tutorial
1502
276
CSS tutorial for creating loading spinners and animations CSS tutorial for creating loading spinners and animations Jul 07, 2025 am 12:07 AM

There are three ways to create a CSS loading rotator: 1. Use the basic rotator of borders to achieve simple animation through HTML and CSS; 2. Use a custom rotator of multiple points to achieve the jump effect through different delay times; 3. Add a rotator in the button and switch classes through JavaScript to display the loading status. Each approach emphasizes the importance of design details such as color, size, accessibility and performance optimization to enhance the user experience.

Addressing CSS Browser Compatibility issues and prefixes Addressing CSS Browser Compatibility issues and prefixes Jul 07, 2025 am 01:44 AM

To deal with CSS browser compatibility and prefix issues, you need to understand the differences in browser support and use vendor prefixes reasonably. 1. Understand common problems such as Flexbox and Grid support, position:sticky invalid, and animation performance is different; 2. Check CanIuse confirmation feature support status; 3. Correctly use -webkit-, -moz-, -ms-, -o- and other manufacturer prefixes; 4. It is recommended to use Autoprefixer to automatically add prefixes; 5. Install PostCSS and configure browserslist to specify the target browser; 6. Automatically handle compatibility during construction; 7. Modernizr detection features can be used for old projects; 8. No need to pursue consistency of all browsers,

What is the difference between display: inline, display: block, and display: inline-block? What is the difference between display: inline, display: block, and display: inline-block? Jul 11, 2025 am 03:25 AM

Themaindifferencesbetweendisplay:inline,block,andinline-blockinHTML/CSSarelayoutbehavior,spaceusage,andstylingcontrol.1.Inlineelementsflowwithtext,don’tstartonnewlines,ignorewidth/height,andonlyapplyhorizontalpadding/margins—idealforinlinetextstyling

Styling visited links differently with CSS Styling visited links differently with CSS Jul 11, 2025 am 03:26 AM

Setting the style of links you have visited can improve the user experience, especially in content-intensive websites to help users navigate better. 1. Use CSS's: visited pseudo-class to define the style of the visited link, such as color changes; 2. Note that the browser only allows modification of some attributes due to privacy restrictions; 3. The color selection should be coordinated with the overall style to avoid abruptness; 4. The mobile terminal may not display this effect, and it is recommended to combine it with other visual prompts such as icon auxiliary logos.

Creating custom shapes with css clip-path Creating custom shapes with css clip-path Jul 09, 2025 am 01:29 AM

Use the clip-path attribute of CSS to crop elements into custom shapes, such as triangles, circular notches, polygons, etc., without relying on pictures or SVGs. Its advantages include: 1. Supports a variety of basic shapes such as circle, ellipse, polygon, etc.; 2. Responsive adjustment and adaptable to mobile terminals; 3. Easy to animation, and can be combined with hover or JavaScript to achieve dynamic effects; 4. It does not affect the layout flow, and only crops the display area. Common usages are such as circular clip-path:circle (50pxatcenter) and triangle clip-path:polygon (50%0%, 100 0%, 0 0%). Notice

How to create responsive images using CSS? How to create responsive images using CSS? Jul 15, 2025 am 01:10 AM

To create responsive images using CSS, it can be mainly achieved through the following methods: 1. Use max-width:100% and height:auto to allow the image to adapt to the container width while maintaining the proportion; 2. Use HTML's srcset and sizes attributes to intelligently load the image sources adapted to different screens; 3. Use object-fit and object-position to control image cropping and focus display. Together, these methods ensure that the images are presented clearly and beautifully on different devices.

Demystifying CSS Units: px, em, rem, vw, vh comparisons Demystifying CSS Units: px, em, rem, vw, vh comparisons Jul 08, 2025 am 02:16 AM

The choice of CSS units depends on design requirements and responsive requirements. 1.px is used for fixed size, suitable for precise control but lack of elasticity; 2.em is a relative unit, which is easily caused by the influence of the parent element, while rem is more stable based on the root element and is suitable for global scaling; 3.vw/vh is based on the viewport size, suitable for responsive design, but attention should be paid to the performance under extreme screens; 4. When choosing, it should be determined based on whether responsive adjustments, element hierarchy relationships and viewport dependence. Reasonable use can improve layout flexibility and maintenance.

What are common CSS browser inconsistencies? What are common CSS browser inconsistencies? Jul 26, 2025 am 07:04 AM

Different browsers have differences in CSS parsing, resulting in inconsistent display effects, mainly including the default style difference, box model calculation method, Flexbox and Grid layout support level, and inconsistent behavior of certain CSS attributes. 1. The default style processing is inconsistent. The solution is to use CSSReset or Normalize.css to unify the initial style; 2. The box model calculation method of the old version of IE is different. It is recommended to use box-sizing:border-box in a unified manner; 3. Flexbox and Grid perform differently in edge cases or in old versions. More tests and use Autoprefixer; 4. Some CSS attribute behaviors are inconsistent. CanIuse must be consulted and downgraded.

See all articles