gpt4 book ai didi

css - 显示文本的剪辑路径替代方案

转载 作者:行者123 更新时间:2023-11-28 11:21:32 25 4
gpt4 key购买 nike

我正在尝试实现这样的东西

body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #8ce2ea;
flex-direction: column;
}

.reveal-text,
.reveal-text::after {
-webkit-animation-delay: 2s;
animation-delay: 2s;
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
-webkit-animation-duration: 800ms;
animation-duration: 800ms;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1);
animation-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1);
}

.reveal-text {
position: relative;
font-size: 10vw;
display: block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-animation-name: reveal-text;
animation-name: reveal-text;
color: #FFF;
white-space: nowrap;
cursor: default

}

.reveal-text::after {
content: "";
position: absolute;
z-index: 999;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #f2f98b;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: 0 50%;
transform-origin: 0 50%;
pointer-events: none;
-webkit-animation-name: revealer-text;
animation-name: revealer-text;
}


@-webkit-keyframes reveal-text {
from {
-webkit-clip-path: inset(0 100% 0 0);
clip-path: inset(0 100% 0 0);
}
to {
-webkit-clip-path: inset(0 0 0 0);
clip-path: inset(0 0 0 0);
}
}


@keyframes reveal-text {
from {
-webkit-clip-path: inset(0 100% 0 0);
clip-path: inset(0 100% 0 0);
}
to {
-webkit-clip-path: inset(0 0 0 0);
clip-path: inset(0 0 0 0);
}
}


@-webkit-keyframes revealer-text {

0%, 50% {
-webkit-transform-origin: 0 50%;
transform-origin: 0 50%;
}

60%, 100% {
-webkit-transform-origin: 100% 50%;
transform-origin: 100% 50%;
}


60% {
-webkit-transform: scaleX(1);
transform: scaleX(1);
}

100% {
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
}


@keyframes revealer-text {

0%, 50% {
-webkit-transform-origin: 0 50%;
transform-origin: 0 50%;
}

60%, 100% {
-webkit-transform-origin: 100% 50%;
transform-origin: 100% 50%;
}


60% {
-webkit-transform: scaleX(1);
transform: scaleX(1);
}

100% {
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
}
<h1 class="reveal-text">
I'm here.
</h1>

但问题是由于 clip-path(文本从一开始就显示)

@keyframes reveal-text {
from {
clip-path: inset(0 100% 0 0);
}
to {
clip-path: inset(0 0 0 0);
}
}

有什么不同的方法可以使它在边缘工作吗?

(我读过 clip-path 在 svg 边缘工作,我应该创建一个带有文本的 svg 吗?)

最佳答案

这是您不必使用clip-path 的另一种方式。只需依靠将覆盖您的文本的背景颜色。你不会有透明度,但你会得到更好的支持。

body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #8ce2ea;
margin:0;
}

.reveal-text {
position: relative;
font-size: 10vw;
color: #FFF;
}

.reveal-text::after {
content: "";
position: absolute;
z-index: 999;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image:
linear-gradient(#f2f98b, #f2f98b),
linear-gradient(#8ce2ea, #8ce2ea);
background-size: 0% 100%, 100% 100%;
background-repeat: no-repeat;
background-position: left, right;
animation: revealer-text 0.8s 2s cubic-bezier(0.0, 0.0, 0.2, 1) forwards;
}

@keyframes revealer-text {
0% {
background-size: 0% 100%, 100% 100%;
background-position: left, right;
}
50% {
background-size: 100% 100%, 0% 100%;
background-position: left, right;
}
51% {
background-size: 100% 100%, 0% 100%;
background-position: right;
}
100% {
background-size: 0% 100%, 0% 100%;
background-position: right;
}
}
<h1 class="reveal-text">
I'm here.
</h1>

关于css - 显示文本的剪辑路径替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53187065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com