【发布时间】:2017-12-24 02:17:22
【问题描述】:
此按钮是否有更好的版本或延迟较小的版本?
我试图找到这种确切类型的样式按钮,但我找不到。这是一个非常糟糕的尝试,需要大量重构,因为我从一开始就没有考虑正确的样式。
任何链接或更高效的代码将不胜感激
我见过类似的代码,但是它只是这种精确的线条样式,基本上是在我想要的按钮周围绘制和删除的(这只是一个漫谈,因为“要求”有更多的描述而不是代码)
.UnderlineButton {
border: none;
background-color: white;
position: relative;
border: 2px solid;
border-top-color: rgb(255,255,255);
border-right-color: rgb(255,255,255);
border-left-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
padding: 10px;
padding-top: 20px;
padding-bottom: 0;
cursor: pointer;
-webkit-animation: UnderlineButton .5s forwards;
}
@-webkit-keyframes UnderlineButton {
0% {
padding-top: 10px;
padding-bottom: 10px;
border-right-color: red;
border-bottom-color: rgb(255,255,255);
border-top-color: red;
border-left-color: red;
}
19% {
border-right-color: red;
}
20% {
border-right-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
border-top-color: red;
border-left-color: red;
}
39% {
border-top-color: red;
}
40% {
border-right-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
border-top-color: rgb(255,255,255);
border-left-color: red;
}
59% {
border-left-color: red;
}
60 {
border-right-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
border-top-color: rgb(255,255,255);
border-left-color: rgb(255,255,255);
}
100% {
padding-top: 20px;
padding-bottom: 0;
border-right-color: rgb(255,255,255);
border-top-color: rgb(255,255,255);
border-left-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
}
}
.UnderlineButton:hover {
-webkit-animation: UnderlineButtonHover .5s forwards;
}
@-webkit-keyframes UnderlineButtonHover {
0% {
padding-top: 20px;
padding-bottom: 0;
border-right-color: rgb(255,255,255);
border-top-color: rgb(255,255,255);
border-left-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
}
20% {
padding-top: 20px;
padding-bottom: 0;
border-right-color: rgb(255,255,255);
border-top-color: rgb(255,255,255);
border-left-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
}
39% {
border-right-color: rgb(255,255,255);
}
40% {
border-right-color: red;
border-left-color: rgb(255,255,255);
border-top-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
}
59% {
border-top-color: rgb(255,255,255);
}
60% {
border-right-color: red;
border-top-color: red;
border-left-color: rgb(255,255,255);
border-bottom-color: rgb(255,255,255);
}
79% {
border-left-color: rgb(255,255,255);
}
80% {
border-right-color: red;
border-top-color: red;
border-left-color: red;
border-bottom-color: rgb(255,255,255);
}
99% {
border-bottom-color: red;
}
100% {
padding-top: 10px;
padding-bottom: 10px;
border-right-color: red;
border-bottom-color: red;
border-top-color: red;
border-left-color: red;
}
}
.UnderlineButton:before {
position: absolute;
bottom: -2px;
background-color: red;
width: 80%;
height: 2px;
content: "";
right: 10%;
-webkit-animation: UnderlineButtonBefore .5s forwards;
}
@-webkit-keyframes UnderlineButtonBefore {
0% {
top: 100%;
width: 100%;
left: 0;
right: 0;
height: 2px;
}
20% {
left: 100%;
right: 0;
height: 2px;
width: 2px;
top: 100%;
}
21% {
top: 0;
width: 2px;
height: 100%;
right: 0;
left: 100%;
}
40% {
top: 0;
width: 2px;
height: 2px;
right: 0;
left: 100%;
}
41% {
top: -2px;
width: 100%;
height: 2px;
right: 0;
left: 0;
}
60% {
top: -2px;
width: 2px;
height: 2px;
left: 0;
}
61% {
top: 0;
width: 2px;
height: 100%;
left: -2px;
bottom: 0;
}
80% {
top: 100%;
bottom: 0;
width: 2px;
height: 0;
left: -2px;
bottom: 0;
}
90% {
bottom: -2px;
left: 0;
width: 0;
height: 2px;
}
100% {
right: 10%;
left: 10%;
width: 80%;
bottom: -2px;
height: 2px;
}
}
.UnderlineButton:hover:before {
-webkit-animation: UnderlineButtonBeforeHover .5s forwards;
}
@-webkit-keyframes UnderlineButtonBeforeHover {
0% {
right: 10%;
width: 80%;
left: 10%;
}
20% {
right: 0;
width: 2px;
height: 2px;
bottom: -2px;
left: 100%;
}
21% {
right: 0;
width: 2px;
height: 2px;
top: 100%;
}
40% {
width: 2px;
height: 100%;
top: 0;
right: -2px;
}
41% {
top: -2px;
height: 2px;
width: 2px;
left: 100%;
}
60% {
width: 100%;
height: 2px;
left: 0;
top: -2px;
}
61% {
width: 2px;
height: 2px;
top: -2px;
left: -2px;
}
80% {
height: 100%;
width: 2px;
top: -2px;
left: -2px;
}
81% {
height: 2px;
width: 2px;
bottom: -2px;
left: -2px;
top: 100%;
}
100% {
top: 100%;
width: 100%;
left: 0;
height: 2px;
}
}
<div style="padding: 40px; background-color:rgb(252,252,252);">
<button class="UnderlineButton">Underline</button>
</div>
【问题讨论】:
-
您的问题到底是什么?什么不符合您的预期?
-
它看起来很慢,我想要一个更好的这个按钮版本。很抱歉造成混乱
-
FWIW,没有看到滞后。我觉得很好。
标签: css user-interface animation transition