当前位置:网站首页>Svg text stroke effect
Svg text stroke effect
2022-06-13 08:24:00 【tingkeaiii】
One 、 effect :

Two 、 Code :
only js part
let str = document.querySelectorAll('.bless path');
for (let i = 0; i < str.length; i++) {
let ilengh = parseInt(str[i].getTotalLength());
str[i].style.strokeDasharray = ilengh + 'px';/*getTotalLength() obtain svg Length rounding *//* The length of the dotted line 、 spacing */
str[i].style.strokeDashoffset = ilengh + 'px';/* Offset ;*/
console.log(ilengh);
}
/* Fill color */
function fill() {
for (let i = 0; i < str.length; i++) {
str[i].style.fill = '#f6d51e';
}
}
for (let i = 0; i < str.length; i++) {
str[i].style.strokeDashoffset = 0;
str[i].style.transition = '2s all';
setTimeout('fill()', 2000);/* Fill in two seconds */
}3、 ... and 、 Ideas
The general idea is , Set a dotted line for each word , And make the dotted line offset so that the font is invisible . Add transition to it , Set the offset value to 0, Then the dotted line is visible . Fill each word with color .
step :
- Make svg, Go to figma Online production Figma. Write the words you want , Right click
Set stroke . Add the color you want to the stroke
, Remove the fill color . Right click to copy to svg. - hold svg Copy into structure , You can get the words . Each of them path Every word . There are as many words as there are path

- Traversal array , Get each path. Put their style in stroke-dasharray and stroke-dashoffset Property is set to this path The length of , It can make path The outer contour of is not visible .stroke-dasharray Property is to set the length of the dotted line ,stroke-dashoffest Is to set the offset value of the dotted line . The offset value is exactly the left shift , Negative is right
- For each path The length of , It's using svg Of getTotalLength( ) Method . For details, please refer to SVG Of getTotalLength(), getPointAtLength() Method introduction _352328759 The blog of -CSDN Blog _gettotallength svg
5. Set the length of the dashed line equal to the offset value path The length of , This string of words is hidden . Let the offset value be equal to 0, Add a transition , Can achieve the effect of font stroke
6. Last , Call the function in a few seconds , Make this string of words filled with color
Reference resources :5 Minutes to learn SVG Text stroke animation _ Bili, Bili _bilibili
边栏推荐
- ERP基础数据 华夏
- Dfinity (ICP) identity authentication and ledger quick start-3
- Do not update the sub component page of parameter object passed from parent to child of nailing applet?
- HCIP_ Static experiment
- How to install the bdtab (BD) new tab plug-in in edge browser (Graphic tutorial)
- [complete information static game characteristics of Nash equilibrium]
- Format_ String_ Server
- Edge browser uses bdtab new tab plug-in (BD new tab)
- 将solidworks建的机器人模型导入到ros中
- sizeof、strlen求字符长度
猜你喜欢
![[notes] like the solution to the problem of slow query (index + explicitly specifying query fields)](/img/95/2109ddf1a0ff0223109eb9b5a02f00.jpg)
[notes] like the solution to the problem of slow query (index + explicitly specifying query fields)

How to install the bdtab (BD) new tab plug-in in edge browser (Graphic tutorial)
![[game theory complete information static game] Application of Nash equilibrium](/img/22/5fd28415cba6ee67878249b4aabb2e.jpg)
[game theory complete information static game] Application of Nash equilibrium

Buuctf web (V)

JS - max. of array cases

JS - array de duplication in the array object case

Dfinity (ICP) identity authentication and ledger quick start-3

JS - for cycle case: Horse grain

Guidance process and service control

使用kvm创建三台能通局域网的虚拟机
随机推荐
JS - set countdown for Date object case
[virt-manager]远程管理启动虚拟机时,鼠标飘逸的问题
Rust writes near smart contract
How to dynamically delete data rows in a table through JS (keep the head)
PHP isset() method ignores data error handling caused by null parameter value
SQL injection experiment
logstash配置参考文章
JS to download files in batches
MySQL installation and configuration under Windows
The method of SolidWorks modifying text font in engineering drawing
How to modify desktop path in win10 system
Edge browser uses bdtab new tab plug-in (BD new tab)
JS - simple ATM of the for cycle case
Reverse order and comparison of strings
Microservice project construction III: automatic code generation
Methods of importing and exporting settings in Altium Designer
How about a well-known food material distribution information management system?
Verify the word limit of textarea input box. Only prompt but no submission limit
How to use annotations in word
将solidworks建的机器人模型导入到ros中