【发布时间】:2021-01-13 04:53:13
【问题描述】:
我正在尝试使文本“示例文本示例文本”在弯曲路径上来回移动。正如您在 sn-p 中看到的那样,我已经能够在一条直线上来回移动,但我不知道如何弯曲它并让它沿着弯曲的路径前进。另外,如果有人可以在文本到达路径的尽头时帮助我加快“轻松”速度,那就太好了。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@500&display=swap" rel="stylesheet">
<title>Document</title>
<style>
*{
margin: 0rem;
padding: 0rem;
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
body {
background: #1B2A41;
}
.container {
margin: auto;
width: 20rem;
background-color: transparent;
}
.path {
position: absolute;
overflow: hidden;
top: 15rem;
left: 15rem;
width: 165rem;
height: 40rem;
background-color: none;
margin: auto;
transform: rotate(20deg);
}
.shape {
position: absolute;
left: 0;
background-color: none;
height: 12rem;
display: block;
top: 40%;
text-align: center;
font-size: 5rem;
font-family: 'Quicksand', sans-serif;
color: #c4def5;
text-shadow: 0 0 20px #4e91ac;
x-transition: all 1s ;
animation: ani 10s infinite;
}
.shape:after {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
padding: 0 20px;
z-index: -1;
color: #8db9e0;
filter: blur(15px);
}
@keyframes ani {
0% {
left: 0rem;
}
50% {
left: 50rem;
}
100% {
left: 0rem;
}
}
</style>
<script>
console.log('hello world')
//#8db9e0
</script>
</head>
<body>
<div class="container">
<div class="path">
<span id="elem" class="shape trail"><h1 data-text='[sample text sample text]'>sample text sample text</h1></span>
</div>
</div>
</body>
</html>
【问题讨论】:
-
搜索了一下发现这个链接:tobiasahlin.com/blog/curved-path-animations-in-css。这是你想要达到的目标吗?
-
您可以使用关键帧和图层来分道扬镳,但最终可能会分别为每个角色设置动画,因为关键帧基本上会沿直线移动物体。沿路径的 SVG 动画可能正是您所寻找的。span>