【发布时间】:2021-06-14 19:09:34
【问题描述】:
我有登陆页面(一页)网站。我在登录页面的中心有文本,用 CSS 动画突出显示。不幸的是,突出显示此文本的 CSS 动画是在进入网站后立即执行的。我怎样才能阻止它?如何使动画仅在出现在屏幕上时才使用文本运行。现在,当用户滚动并且它可以工作时,文本就会显示出来。不幸的是,下划线在进入网站后移动得更早。当用户滚动页面时,文本带有下划线:(
<h2 class=" title animated" data-animate="fadeInUp" data-delay=".4">lorem <span class="text-nice-underline">ipsum</span> <span class="text-nice-underline2" >example</span> template</h2>
.text-nice-underline {
position: relative;
}
.text-nice-underline:after {
content: "";
display: inline-block;
position: absolute;
width: 100%;
height: 100%;
z-index: -1; /* Place the pseudo element right under the content */
top: 0;
left: 0;
background: linear-gradient(to top, #ffbc42 22%, transparent 24%);
animation-name: highlight;
animation-duration: 2.95s;
animation-delay: 0.8s;
animation-fill-mode: both;
}
.text-nice-underline2 {
position: relative;
}
.text-nice-underline2:after {
content: "";
display: inline-block;
position: absolute;
width: 100%;
height: 100%;
z-index: -1; /* Place the pseudo element right under the content */
top: 0;
left: 0;
background: linear-gradient(to top, #ffbc42 22%, transparent 24%);
animation-name: highlight;
animation-duration: 3.95s;
animation-delay: 1.4s;
animation-fill-mode: both;
}
.text-nice-underline2:hover, .text-nice-underline:hover {
background: linear-gradient(to top, #ffbc42 95%, transparent 95%);
}
@keyframes highlight {
0% {
width: 0;
opacity: 0;
}
90% {
width: 100%;
opacity: 1;
}
}
【问题讨论】:
标签: javascript html css mobile-website