


How to use CSS to achieve dynamic effects of color-changing rotation animation
This article introduces to you how to use CSS to achieve the dynamic effect of color-changing rotation animation. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Effect preview
Code interpretation
Definition of dom, container Contains 9 elements:
<div> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div>
Centered display:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: black; }
Define the container size:
.container { width: 30em; height: 30em; font-size: 12px; }
Set the style of the lines in the container:
.container { color: lime; } .container span { position: absolute; width: 5em; height: 5em; border-style: solid; border-width: 1em 1em 0 0; border-color: currentColor transparent; border-radius: 50%; }
Let the lines Display in the center of the container:
.container { display: flex; align-items: center; justify-content: center; }
Define variables to gradually extend the line from the center to the outside:
.container span { --diameter: calc(5em + (var(--n) - 1) * 3em); width: var(--diameter); height: var(--diameter); } .container span:nth-child(1) { --n: 1; } .container span:nth-child(2) { --n: 2; } .container span:nth-child(3) { --n: 3; } .container span:nth-child(4) { --n: 4; } .container span:nth-child(5) { --n: 5; } .container span:nth-child(6) { --n: 6; } .container span:nth-child(7) { --n: 7; } .container span:nth-child(8) { --n: 8; } .container span:nth-child(9) { --n: 9; }
Set the animation effect to rotate the line:
.container span { animation: rotating linear infinite; animation-duration: calc(5s / (9 - var(--n) + 1)); } @keyframes rotating { to { transform: rotate(1turn); } }
Define the color change The animation effect is based on 360 degrees of the hue circle as 100%. The --percent variable refers to the position of 100%:
@keyframes change-color { 0%, 100% { --percent: 0; } 10% { --percent: 10; } 20% { --percent: 20; } 30% { --percent: 30; } 40% { --percent: 40; } 50% { --percent: 50; } 60% { --percent: 60; } 70% { --percent: 70; } 80% { --percent: 80; } 90% { --percent: 90; } }
Finally, apply the color-changing animation effect to the container:
.container { --deg: calc(var(--percent) / 100 * 360deg); color: hsl(var(--deg), 100%, 50%); animation: change-color 5s linear infinite; }
Done!
Recommended related articles:
How to use CSS and D3 to achieve the dynamic effect of a spaceship
How to use CSS and D3 to achieve endless six The effect of edge space
The above is the detailed content of How to use CSS to achieve dynamic effects of color-changing rotation animation. For more information, please follow other related articles on the PHP Chinese website!

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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.
