正如标题所示,我正在尝试为虚线箭头设置动画。
我希望它看起来尽可能接近,就像在这个 网站上一样。
我能够制作一个箭头,虽然我不确定这是否是正确的方式。
我想我应该用 SVG 画这个。
而且动画看起来很奇怪,我不知道如何使它更流畅。
这是我的代码:
body {
margin: 0;
font-size: 16px;
line-height: 1.528571429;
padding: 0;
height: 100%;
}
body #contact {
height: calc(100vh - 40px);
background-color: #ffffff;
}
body #contact .to-top-btn-wrapper {
position: absolute;
z-index: 999;
left: 7%;
bottom: 15%;
}
body #contact .to-top-btn-wrapper .btn-text-wrapper {
margin: -35px auto;
}
body #contact .to-top-btn-wrapper .btn-text-wrapper .btn-text {
font-size: 14px;
letter-spacing: 0.25em;
text-align: center;
color: #676565;
text-transform: uppercase;
}
body #contact .to-top-btn-wrapper .to-top-btn {
position: absolute;
top: 0;
left: 35px;
bottom: 25px;
cursor: pointer;
}
body #contact .to-top-btn-wrapper .to-top-btn .line {
border-right: 0.1rem dashed #676565;
display: inline-block;
animation: show 1000ms linear forwards infinite;
}
body #contact .to-top-btn-wrapper .to-top-btn .arrow {
position: absolute;
top: -0.3rem;
bottom: 0;
height: 1rem;
border-right: 0.1rem solid #676565;
display: inline-block;
}
body #contact .to-top-btn-wrapper .to-top-btn .right {
left: 0.3rem;
transform: rotate(-45deg);
}
body #contact .to-top-btn-wrapper .to-top-btn .left {
right: 0.3rem;
transform: rotate(45deg);
}
@keyframes show {
0% {
height: 5rem;
}
100% {
height: 0rem;
}
}
<section id="contact" class="container-fluid">
<div class="to-top-btn-wrapper">
<div class="btn-text-wrapper">
<span class="btn-text">Scroll to top</span>
</div>
<div class="to-top-btn">
<span class="arrow left"></span>
<span class="line"></span>
<span class="arrow right"></span>
</div>
</div>
</section>
问题的免费翻译如何为虚线箭头设置动画?来自成员 winde。

仅适用于正常背景颜色。
因为动画是这样的:
这可以通过动画
clip-path和一些背景来完成:使用面具的类似想法:
这是一个
background没有only 的解决方案clip-path:另一个梯度较小的版本:
并使用 CSS 变量轻松控制一切:
来自成员 @Temani Afif的答案的松散翻译 。
如何做到这一点很有趣,我使用 box-shadow 来绘制“破折号”+ css 动画“正如我所见”。没错,没有箭头本身,只是作为一个概念:
这是解决方案。从视觉上看,与问题中给出的网站上的箭头几乎没有区别。适用于任何背景颜色或图像,不依赖于背景。仅使用 CSS 来解决这个问题,使箭头元素不依赖于背景颜色,很可能是不可能的。所以我不得不求助于 JavaScript。
向下箭头:
向上箭头: