The final effect is as follows: The animation is divided into two steps
Develop running trajectory We first need to draw a light blue semi-transparent road at the bottom as a pipeline for energy flow. We use SVG path here (in fact, we can directly use the background image here). The code is as follows: <!-- The code is written in react, and the traversal and some codes are deleted--> <svg> <!-- Tool description prompt, used in fill for filtering and other operations, here is the glow at the bottom of the ball--> <defs> <radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%"> <stop offset="0%" style={{ stopColor: "rgba(2,246,255,.5)" }} /> <stop offset="100%" style={{ stopColor: "rgba(2,246,255,0)" }} /> </radialGradient> </defs> <!-- Here we traverse N light blue line paths d as the path--> <path d={item.path} stroke="rgba(29,159,167,0.4)" fill="transparent" strokeWidth={5}></path> ... <!-- Here is a luminous ball formed by superimposing two circles--> <g> <circle cx={cx} cy={cy} r="15" fill="url(#grad1)"></circle> <circle cx={cx} cy={cy} r="5" fill="rgba(2,246,255)"></circle> </g> </svg> Create DOM and animate along the path The core principle here is to set the motion offset path through the offset-path property, and then set the offset through the offset-distance, so that the element can move along a certain trajectory through CSS3 animation. <!-- Here we need to ensure that the box and SVG box are aligned, with the same width and height, so that the path points are consistent--> <div className={styles.animate}> <!-- Here we traverse N divs and make each div flow according to the offsetPath, which is the value of d in the path in svg --> <!-- A negative animationDelay means it is executed before rendering, so the entire path can be covered during rendering--> <div key={index} className={styles.point3} style={{ "offsetPath": "path('M 105 34 L 5 34')", "animationDelay": `-${index * 1}s`, "animationDuration": '5s', 'animationPlayState': `${stop ? 'paused' : 'running'}` }}></div> ... </div> .point3 { width: 10px; height: 2px; // offset-path: path('M 248 108 L 248 172 L 1510 172'); offset-distance: 0%; animation: flow 20s linear normal infinite; background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 10%, #FEFE02); position: absolute; left: 0; right: 0; } } @keyframes flow { from { offset-distance: 0%; } to { offset-distance: 100%; } } This is the end of this article about how to use CSS animation with SVG to create energy flow effects. For more information about using CSS animation with SVG, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. We hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Share the pitfalls of MySQL's current_timestamp and their solutions
>>: Server concurrency estimation formula and calculation method
1. Install mutt sudo apt-get install mutt 2. Inst...
Table of contents Single condition single data fi...
Introduction to Linux alarm function Above code: ...
1. Prepare the Docker environment 2. Search for f...
Table of contents Preface Create a Vite project R...
This tag is not part of HTML3.2 and only supports ...
Table of contents Overview 1. Compositon API 1. W...
Description: Set a timer to replace the content of...
This article shares the specific code of vue+echa...
In CSS files, we often see some font names become...
As shown below: select a1,a2,a1+a2 a,a1*a2 b,a1*1...
Table of contents Compare the empty string '&...
Tomcat CentOS Installation This installation tuto...
Table of contents 1. Use the warehouse to create ...
Preface Using css to generate dotted lines is a p...