当前位置:网站首页>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
边栏推荐
- Did decentralized digital identity
- [game theory complete information static game] Application of Nash equilibrium
- Common shell script development specifications
- Start from scratch - implement the jpetstore website -1- establish the project framework and project introduction
- Phpexcel 10008 error resolution
- 星巴克创始人:出于安全考量 或不再向非店内消费者开放“公厕”
- 水仙花升级版(自幂数)
- 【博弈论-完全信息静态博弈】 Nash均衡
- filebeat采集日志到ELK
- Data accuracy problems caused by inconsistent data types during sum in MySQL
猜你喜欢

Process and scheduled task management

HCIP_ MGRE experiment

学习记录4: einops // cudnn.benchamark=true // hook

ERP 基础数据 概念

Buuctf web (VII)

Learning record 4:einops / / cudnn benchamark=true // hook

Maternal and infant supplies wholesale industry uses management software to improve efficiency and realize cost reduction and efficiency increase

钉钉小程序如何隐藏tab

HCIP_ OSPF irregular area
Import the robot model built by SolidWorks into ROS
随机推荐
HCIP_ OSPF irregular area
DNS domain name resolution service
第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
Dfinity (ICP) identity authentication and ledger quick start-3
MySQL query exercise 3
天猫商品详情接口,天猫商品优惠券接口,天猫api接口,天猫价格监控接口,天猫比价接口,品牌维权接口,天猫销量api接口,接口代码可对接数据分析业务,品牌维权,比价业务,行业分析业务接口代码分享
关于redis使用分布式锁的封装工具类
Shell脚本常用开发规范
Request alarm: refer policy: strict origin when cross origin or reference site policy: no refer when downgrade
Wechat upload picture material interface
Live broadcast review | bas technology innovation exploration under active defense system
Is there any good management software to solve the problems faced by tea wholesalers
淘宝商品历史价格接口/商品历史价走势接口代码对接分享
sizeof、strlen求字符长度
Penetration problem (main directory, password explosion, database uploading Trojan horse)
set实现名单查找与排除
平面合并(MATLAB)
Buuctf web (V)
将solidworks建的机器人模型导入到ros中
BD新标签页(BdTab)插件如何登入?