我有一个问题,在这个文本上循环这个梯度,而没有一个恼人的跳跃出现在动画循环上。我希望它能无限平滑地跨下一页移动,这样就不会出现烦人的结巴。你知道我该怎么做吗?
这是我在CodePen上的代码示例,下面是相应的HTML和CSS:
<pre class="header">
88888888888 888 888 8888888888 8888888b. .d88888b. .d8888b. .d8888b. 888 888 888b d888 8888888b. 8888888888 888b 888
888 888 888 888 888 Y88b d88P" "Y88b d88P Y88b d88P Y88b 888 888 8888b d8888 888 "Y88b 888 8888b 888
888 888 888 888 888 888 888 888 Y88b. Y88b. 888 888 88888b.d88888 888 888 888 88888b 888
888 8888888888 8888888 888 d88P 888 888 "Y888b. "Y888b. 888 888 888Y88888P888 888 888 8888888 888Y88b 888
888 888 888 888 8888888P" 888 888 "Y88b. "Y88b. 888 888 888 Y888P 888 888 888 888 888 Y88b888
888 888 888 888 888 888 888 "888 "888 888 888 888 Y8P 888 888 888 888 888 Y88888
888 888 888 888 888 Y88b. .d88P Y88b d88P Y88b d88P Y88b. .d88P 888 " 888 888 .d88P 888 888 Y8888
888 888 888 8888888888 888 "Y88888P" "Y8888P" "Y8888P" "Y88888P" 888 888 8888888P" 8888888888 888 Y888
</pre>
.header{
text-align: center;
font-family: monospace;
display:block;
background-image:
linear-gradient(to right, #ff0000 0%, #ff9a00 10%, #d1de21 20%, #4fdc4a 30%, #3fdad8 40%, #2fc9e2 50%, #1c7fee 60%, #5f15f2 70%, #ba0cf8 80%, #fb07d9 90%, #ff0000 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: move 35s linear infinite;
}
@keyframes move {
to {
background-position: 1600vh;
}
}
任何帮助都将是非常感激的,因为我完全难住了。谢谢你!由于文本是等宽格式,我们可以以ch为单位定义该块的宽度。
将文本放在内部元素中(因此它可以被赋予ch宽度,但仍然位于标题中心),此代码片段使背景从左到右移动文本的宽度(就像问题中的原始文本一样,但没有那么极端的距离)。因为它是重复的,它完全回到了开始,所以没有闪烁。
.header .inner{
--len: 148ch;
width: var(--len);
padding: 0;
margin: 0 auto;
text-align: center;
font-family: monospace;
display:block;
background-image:
linear-gradient(to right, #ff0000 0%, #ff9a00 10%, #d1de21 20%, #4fdc4a 30%, #3fdad8 40%, #2fc9e2 50%, #1c7fee 60%, #5f15f2 70%, #ba0cf8 80%, #fb07d9 90%, #ff0000 100%);
background-position: 0 0, 0 0;
background-color: pink;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: move 1s linear infinite;
}
@keyframes move {
to {
background-position: var(--len) 0, 0 0;
}
}
body{
background:#000000;
}
<div class="header">
<pre class="inner">
88888888888 888 888 8888888888 8888888b. .d88888b. .d8888b. .d8888b. 888 888 888b d888 8888888b. 8888888888 888b 888
888 888 888 888 888 Y88b d88P" "Y88b d88P Y88b d88P Y88b 888 888 8888b d8888 888 "Y88b 888 8888b 888
888 888 888 888 888 888 888 888 Y88b. Y88b. 888 888 88888b.d88888 888 888 888 88888b 888
888 8888888888 8888888 888 d88P 888 888 "Y888b. "Y888b. 888 888 888Y88888P888 888 888 8888888 888Y88b 888
888 888 888 888 8888888P" 888 888 "Y88b. "Y88b. 888 888 888 Y888P 888 888 888 888 888 Y88b888
888 888 888 888 888 888 888 "888 "888 888 888 888 Y8P 888 888 888 888 888 Y88888
888 888 888 888 888 Y88b. .d88P Y88b d88P Y88b d88P Y88b. .d88P 888 " 888 888 .d88P 888 888 Y8888
888 888 888 8888888888 888 "Y88888P" "Y8888P" "Y8888P" "Y88888P" 888 888 8888888P" 8888888888 888 Y888</pre>
</div>
考虑以下不需要任何硬编码值的情况:
.header{
font-family: monospace;
display:inline-block;
color:transparent;
background:
linear-gradient(90deg, #ff0000 0%, #ff9a00 10%, #d1de21 20%, #4fdc4a 30%, #3fdad8 40%, #2fc9e2 50%, #1c7fee 60%, #5f15f2 70%, #ba0cf8 80%, #fb07d9 90%, #ff0000 100%)
left/50% 100%; /* 50% = half the width*/
-webkit-background-clip: text;
background-clip: text;
animation: move 1s linear infinite;
}
@keyframes move {
to {
background-position: right; /* you simply animate to right*/
}
}
body {
background:#000;
text-align: center;
}
<pre class="header">
88888888888 888 888 8888888888 8888888b. .d88888b. .d8888b. .d8888b. 888 888 888b d888 8888888b. 8888888888 888b 888
888 888 888 888 888 Y88b d88P" "Y88b d88P Y88b d88P Y88b 888 888 8888b d8888 888 "Y88b 888 8888b 888
888 888 888 888 888 888 888 888 Y88b. Y88b. 888 888 88888b.d88888 888 888 888 88888b 888
888 8888888888 8888888 888 d88P 888 888 "Y888b. "Y888b. 888 888 888Y88888P888 888 888 8888888 888Y88b 888
888 888 888 888 8888888P" 888 888 "Y88b. "Y88b. 888 888 888 Y888P 888 888 888 888 888 Y88b888
888 888 888 888 888 888 888 "888 "888 888 888 888 Y8P 888 888 888 888 888 Y88888
888 888 888 888 888 Y88b. .d88P Y88b d88P Y88b d88P Y88b. .d88P 888 " 888 888 .d88P 888 888 Y8888
888 888 888 8888888888 888 "Y88888P" "Y8888P" "Y8888P" "Y88888P" 888 888 8888888P" 8888888888 888 Y888
</pre>
<pre class="header" style="font-size:5px">
88888888888 888 888 8888888888 8888888b. .d88888b. .d8888b. .d8888b. 888 888 888b d888 8888888b. 8888888888 888b 888
888 888 888 888 888 Y88b d88P" "Y88b d88P Y88b d88P Y88b 888 888 8888b d8888 888 "Y88b 888 8888b 888
888 888 888 888 888 888 888 888 Y88b. Y88b. 888 888 88888b.d88888 888 888 888 88888b 888
888 8888888888 8888888 888 d88P 888 888 "Y888b. "Y888b. 888 888 888Y88888P888 888 888 8888888 888Y88b 888
888 888 888 888 8888888P" 888 888 "Y88b. "Y88b. 888 888 888 Y888P 888 888 888 888 888 Y88b888
888 888 888 888 888 888 888 "888 "888 888 888 888 Y8P 888 888 888 888 888 Y88888
888 888 888 888 888 Y88b. .d88P Y88b d88P Y88b d88P Y88b. .d88P 888 " 888 888 .d88P 888 888 Y8888
888 888 888 8888888888 888 "Y88888P" "Y8888P" "Y8888P" "Y88888P" 888 888 8888888P" 8888888888 888 Y888
</pre>
另一个变体:
.header{
font-family: monospace;
display:inline-block;
color:transparent;
background:
linear-gradient(90deg, #ff0000 0%, #ff9a00 10%, #d1de21 20%, #4fdc4a 30%, #3fdad8 40%, #2fc9e2 50%, #1c7fee 60%, #5f15f2 70%, #ba0cf8 80%, #fb07d9 90%, #ff0000 100%)
left/200% 100%; /* 200% = twice the width*/
-webkit-background-clip: text;
background-clip: text;
animation: move 1s linear infinite;
}
@keyframes move {
to {
background-position: -200% 0;
}
}
body {
background:#000;
text-align: center;
}
<pre class="header">
88888888888 888 888 8888888888 8888888b. .d88888b. .d8888b. .d8888b. 888 888 888b d888 8888888b. 8888888888 888b 888
888 888 888 888 888 Y88b d88P" "Y88b d88P Y88b d88P Y88b 888 888 8888b d8888 888 "Y88b 888 8888b 888
888 888 888 888 888 888 888 888 Y88b. Y88b. 888 888 88888b.d88888 888 888 888 88888b 888
888 8888888888 8888888 888 d88P 888 888 "Y888b. "Y888b. 888 888 888Y88888P888 888 888 8888888 888Y88b 888
888 888 888 888 8888888P" 888 888 "Y88b. "Y88b. 888 888 888 Y888P 888 888 888 888 888 Y88b888
888 888 888 888 888 888 888 "888 "888 888 888 888 Y8P 888 888 888 888 888 Y88888
888 888 888 888 888 Y88b. .d88P Y88b d88P Y88b d88P Y88b. .d88P 888 " 888 888 .d88P 888 888 Y8888
888 888 888 8888888888 888 "Y88888P" "Y8888P" "Y8888P" "Y88888P" 888 888 8888888P" 8888888888 888 Y888
</pre>
<pre class="header" style="font-size:5px">
88888888888 888 888 8888888888 8888888b. .d88888b. .d8888b. .d8888b. 888 888 888b d888 8888888b. 8888888888 888b 888
888 888 888 888 888 Y88b d88P" "Y88b d88P Y88b d88P Y88b 888 888 8888b d8888 888 "Y88b 888 8888b 888
888 888 888 888 888 888 888 888 Y88b. Y88b. 888 888 88888b.d88888 888 888 888 88888b 888
888 8888888888 8888888 888 d88P 888 888 "Y888b. "Y888b. 888 888 888Y88888P888 888 888 8888888 888Y88b 888
888 888 888 888 8888888P" 888 888 "Y88b. "Y88b. 888 888 888 Y888P 888 888 888 888 888 Y88b888
888 888 888 888 888 888 888 "888 "888 888 888 888 Y8P 888 888 888 888 888 Y88888
888 888 888 888 888 Y88b. .d88P Y88b d88P Y88b d88P Y88b. .d88P 888 " 888 888 .d88P 888 888 Y8888
888 888 888 8888888888 888 "Y88888P" "Y8888P" "Y8888P" "Y88888P" 888 888 8888888P" 8888888888 888 Y888
</pre>
相关问题,以获得更多的细节值:使用百分比值与背景位置的线性梯度