search
HomeWeb Front-endHTML Tutorial【css3】Learn about Transform, Transition and Animation through image carousel_html/css_WEB-ITnose

The author likes to pursue visual enjoyment, although he often sacrifices performance and incompatibility, but he still enjoys it. This article will briefly understand Transform, Transition and Animation under CSS3 through demo demonstrations one by one.

This article needs to achieve the effect: (Please use chrome to open )

  • Picture carousel
  • Automatic picture carousel
  • Transform

    According to my understanding, transform, like width, height, and background, are all attributes of dom. The difference is that it is under css3. Compared with ?, it can move, scale, rotate, and adjust the original dom elements. Stretching or stretching is similar to some APIs on canvas. It seems that transform can do something that can only be done by js.

    Transform is divided into 2D transformation and 3D transformation. There are good introductions and examples in w3school. For details, please click: CSS3 2D transformation CSS3 3D transformation

    In order to facilitate the search, I put the Save a screenshot here:

    Transition

    The explanation of transition is transition. My understanding is the transformation between CSS, but this transformation is very smooth. Similar to animation. For example, the class of a certain DOM is classA at the beginning, and after some operation (such as being clicked), it becomes classB. If there is no transition, the transformation between classes is very fast, and it is completed instantly like a machine. However, With transition, this will be a very gentle and smooth process.

    We use demo to explain how to use transition.

    Write the following html file:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css"></style>  <img  src='http://hanzichi.github.io/img/img0.png' / alt="【css3】Learn about Transform, Transition and Animation through image carousel_html/css_WEB-ITnose" >

    It opens to a very simple picture, add css:

    img {  -webkit-transition: all 1s ease-in-out 0s;}img:hover {  -webkit-transform:     rotate(360deg)    scale(0.5, 0.5);  opacity: 0;}

    Please click on the effect: transition transformation (ps: All demos are not compatible, please use chrome to open it )

    Is it very simple? In the demo, you only need to set the original attributes and attributes of the image (img tag) after hovering, and the transition process is all handled by transition! The transition is added under a certain element (the transition of the demo is added under the img tag), as if a listener is set. Once the attribute value of the element is about to change, the set attributes in the transition will be automatically checked. Once If a match is found, a smooth transition will be made.

    Transition has 4 properties, syntax: transition: property duration timing-function delay The 4 properties from front to back can be understood as "transition animation transformation properties" ", "Transition time spent", "Speed ​​change of transition process" and "Waiting time before transition starts" (default value: all 0 ease 0 The first two are required and the last two can be omitted).

    If not all attributes need to be smoothly transitioned, or each attribute transition time, speed and other settings have different requirements, you can separate the attributes to be transitioned with commas, and the demo can be written as:

    img {  -webkit-transition:     -webkit-transform 1s ease-in-out 0s,    opacity 1s ease-in-out 1s;}img:hover {  -webkit-transform:     rotate(360deg)    scale(0.5, 0.5);  opacity: 0;}

    If you have to write the four attributes of transition separately, you can do this:

    img {  -webkit-transition-property: -webkit-transform, opacity;  -webkit-transition-duration: 1s;  -webkit-transition-timing-function: ease-in-out;  -webkit-transition-delay: 0s;}

    I put the last three attributes together and just After writing a value (because the values ​​are the same), you can also write them separately like properties, separated by commas.

    Here we will introduce the value of timing-function. Six major values: (still stolen picture w3cschool)

    Summary: Generally, transition is used in dom class transformation. You can write the mechanical transformation first, and then add the transition effect.

    Animation

    The explanation of Animation is animation, an enhanced version of transition.

    If transition can achieve certain js effects, animation is more like js. Similar to writing a canvas special effect, the total time of the special effect, for example, we can specify when and what kind of scene should appear, and the conversion between each scene is completely responsible for CSS3 itself, and keyframes are like defining a js method.

    Mainly used when a certain element requires n consecutive css transformations. A simple demo is as follows: animation

    When we create animation in @keyframes, please bind it to a selector, otherwise the animation effect will not be produced.

    You can bind an animation to a selector by specifying at least two of the following CSS3 animation properties:

  • Specify the name of the animation
  • Specify the duration of the animation
  • Demo code:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">  img {    /*-webkit-animation: myfirst 5s;*/  }    @-webkit-keyframes myfirst  {    0% {      -webkit-transform:         rotate(0deg)        scale(1, 1);      opacity: 1;    }        50% {      -webkit-transform:         rotate(360deg)        scale(0.5, 0.5);      opacity: 0.5;    }        100% {      -webkit-transform:         rotate(0deg)        scale(1, 1)        translate(300px, 200px);      opacity: 1;    }  }  img {    -webkit-animation: myfirst 5s linear 0s 1 alternate;    /*停在结束位置*/    -webkit-animation-fill-mode: forwards;  }</style>  <img  src='http://hanzichi.github.io/img/img0.png' / alt="【css3】Learn about Transform, Transition and Animation through image carousel_html/css_WEB-ITnose" >

    For more information, please click CSS3 animation

    Specific application: Image carousel

    For similar applications, you can first write the code without transition, and then add transition between class conversions.

    The demo (automatic image rotation) has only a few lines of core code related to transition, while js simply assigns values ​​to the elements’ classes, and the animation process is all completed by css3!

    img {  position: absolute;  -webkit-transition: all 2s ease-out;}.disappear {  opacity: 0;}.show {  opacity: 1;}

    When the img class is converted from show to disappear or from disappear to show (class transformation under the img tag), the transition animation set by the transition will be executed.

    The implementation of the other demo is also similar. If you are interested, you can refer to the source code: Please click on the source code

    Summary

    Generally speaking, transform just adds some attributes to the dom, and if combined with transition or animation, some animation effects can be achieved. I think transition is more commonly used in practice, and can be used with pseudo-classes or click events.

    The poster does not have a deep understanding of the above. If there is any discrepancy, please point it out.

    If you want to know more, you can refer to this article Introduction and Application Demonstration of CSS3 Transitions, Transforms and Animation

    Statement
    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
    The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

    The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

    HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

    The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

    HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

    HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

    HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

    HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

    From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

    HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

    Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

    WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

    The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

    The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

    HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

    HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

    See all articles

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Chat Commands and How to Use Them
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    EditPlus Chinese cracked version

    EditPlus Chinese cracked version

    Small size, syntax highlighting, does not support code prompt function

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment