


【css3】Learn about Transform, Transition and Animation through image carousel_html/css_WEB-ITnose
Jun 24, 2016 am 11:48 AM
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 )
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' />
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:
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; /*停在結(jié)束位置*/ -webkit-animation-fill-mode: forwards; }</style> <img src='http://hanzichi.github.io/img/img0.png' />
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

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The key to keep up with HTML standards and best practices is to do it intentionally rather than follow it blindly. First, follow the summary or update logs of official sources such as WHATWG and W3C, understand new tags (such as) and attributes, and use them as references to solve difficult problems; second, subscribe to trusted web development newsletters and blogs, spend 10-15 minutes a week to browse updates, focus on actual use cases rather than just collecting articles; second, use developer tools and linters such as HTMLHint to optimize the code structure through instant feedback; finally, interact with the developer community, share experiences and learn other people's practical skills, so as to continuously improve HTML skills.

The reason for using tags is to improve the semantic structure and accessibility of web pages, make it easier for screen readers and search engines to understand page content, and allow users to quickly jump to core content. Here are the key points: 1. Each page should contain only one element; 2. It should not include content that is repeated across pages (such as sidebars or footers); 3. It can be used in conjunction with ARIA properties to enhance accessibility. Usually located after and before, it is used to wrap unique page content, such as articles, forms or product details, and should be avoided in, or in; to improve accessibility, aria-labeledby or aria-label can be used to clearly identify parts.

To create a basic HTML document, you first need to understand its basic structure and write code in a standard format. 1. Use the declaration document type at the beginning; 2. Use the tag to wrap the entire content; 3. Include and two main parts in it, which are used to store metadata such as titles, style sheet links, etc., and include user-visible content such as titles, paragraphs, pictures and links; 4. Save the file in .html format and open the viewing effect in the browser; 5. Then you can gradually add more elements to enrich the page content. Follow these steps to quickly build a basic web page.

To create an HTML checkbox, use the type attribute to set the element of the checkbox. 1. The basic structure includes id, name and label tags to ensure that clicking text can switch options; 2. Multiple related check boxes should use the same name but different values, and wrap them with fieldset to improve accessibility; 3. Hide native controls when customizing styles and use CSS to design alternative elements while maintaining the complete functions; 4. Ensure availability, pair labels, support keyboard navigation, and avoid relying on only visual prompts. The above steps can help developers correctly implement checkbox components that have both functional and aesthetics.

To reduce the size of HTML files, you need to clean up redundant code, compress content, and optimize structure. 1. Delete unused tags, comments and extra blanks to reduce volume; 2. Move inline CSS and JavaScript to external files and merge multiple scripts or style blocks; 3. Simplify label syntax without affecting parsing, such as omitting optional closed tags or using short attributes; 4. After cleaning, enable server-side compression technologies such as Gzip or Brotli to further reduce the transmission volume. These steps can significantly improve page loading performance without sacrificing functionality.

HTMLhasevolvedsignificantlysinceitscreationtomeetthegrowingdemandsofwebdevelopersandusers.Initiallyasimplemarkuplanguageforsharingdocuments,ithasundergonemajorupdates,includingHTML2.0,whichintroducedforms;HTML3.x,whichaddedvisualenhancementsandlayout

It is a semantic tag used in HTML5 to define the bottom of the page or content block, usually including copyright information, contact information or navigation links; it can be placed at the bottom of the page or nested in, etc. tags as the end of the block; when using it, you should pay attention to avoid repeated abuse and irrelevant content.

To embed videos in HTML, use tags and specify the video source and attributes. 1. Use src attributes or elements to define the video path and format; 2. Add basic attributes such as controls, width, height; 3. To be compatible with different browsers, you can list MP4, WebM, Ogg and other formats; 4. Use controls, autoplay, muted, loop, preload and other attributes to control the playback behavior; 5. Use CSS to realize responsive layout to ensure that it is adapted to different screens. Correct combination of structure and attributes can ensure good display and functional support of the video.
