如何使一个按钮,动画悬停像Airforce.com发现按钮

问题描述 投票:3回答:2

如何使悬停就像或在这种GIF发现按钮上airforce.com发现的那些按钮动画。

html css html5 css3 css-animations
2个回答
7
投票

下面是一个元素和多种背景的想法:

.box {
  display:inline-block;
  padding:10px 20px;
  border-right:1px solid;
  border-left:1px solid;
  background:
      linear-gradient(#000,#000) top left,
      linear-gradient(#000,#000) top right,
      linear-gradient(#000,#000) bottom right,
      linear-gradient(#000,#000) bottom left;
  background-size:15% 1px,75% 1px;
  background-repeat:no-repeat;
  transition:.8s all;
}
.box:hover {
  background-size:75% 1px,15% 1px;
}
<div class="box">
  some text
</div>

<div class="box">
  more and more text
</div>

如果你想空白是固定的,你可以调整background-size。下面是10px用于开始在距边缘10px透明部分的例子。

.box {
  display:inline-block;
  padding:10px 20px;
  border-right:1px solid;
  border-left:1px solid;
  background:
      linear-gradient(#000,#000) top left,
      linear-gradient(#000,#000) top right,
      linear-gradient(#000,#000) bottom right,
      linear-gradient(#000,#000) bottom left;
  background-size:10px 1px,calc(100% - 20px) 1px;
  background-repeat:no-repeat;
  transition:.8s all;
}
.box:hover {
  background-size:calc(100% - 20px) 1px,10px 1px;
}
<div class="box">
  some text
</div>

<div class="box">
  more and more text
</div>

另一个想法梯度也:

.box {
  display:inline-block;
  padding:10px 20px;
  border-right:1px solid;
  border-left:1px solid;
  background:
      linear-gradient(to right,
        #000 calc(50% - 5px),transparent calc(50% - 5px),
        transparent calc(50% + 5px),#000 calc(50% + 5px)),
      linear-gradient(to right,
        #000 calc(50% - 5px),transparent calc(50% - 5px),
        transparent calc(50% + 5px),#000 calc(50% + 5px));       
  background-size:150% 1px;
  background-position:top left,bottom right;
  background-repeat:no-repeat;
  transition:.8s all;
}
.box:hover {
  background-position:top right,bottom left;
}
<div class="box">
  some text
</div>

<div class="box">
  more and more text
</div>

6
投票

尝试动画的边界,但这样只是做::after::before的按钮非常复杂,那么它的动画。

body {
  display: flex;
  flex-direction: column;
  height: 93vh;
  justify-content: center;
  align-items: center;
  background: #222;
  color: #eee;
  font-family: monospace;
}

.brk-btn {
  position: relative;
  background: none;
  color: aqua;
  text-transform: uppercase;
  text-decoration: none;
  border: 0.2em solid aqua;
  margin-top: 1em;
  padding: 0.5em 1em;
}

.brk-btn::before {
  content: "";
  display: block;
  position: absolute;
  width: 10%;
  background: #222;
  height: 0.3em;
  right: 20%;
  top: -0.21em;
  transform: skewX(-45deg);
  -webkit-transition: all 0.45s cubic-bezier(0.86, 0, 0.07, 1);
  transition: all 0.45s cubic-bezier(0.86, 0, 0.07, 1);
}

.brk-btn::after {
  content: "";
  display: block;
  position: absolute;
  width: 10%;
  background: #222;
  height: 0.3em;
  left: 20%;
  bottom: -0.25em;
  transform: skewX(45deg);
  -webkit-transition: all 0.45 cubic-bezier(0.86, 0, 0.07, 1);
  transition: all 0.45s cubic-bezier(0.86, 0, 0.07, 1);
}

.brk-btn:hover::before {
  right: 80%;
}

.brk-btn:hover::after {
  left: 80%;
}

.underlined-a {
  text-decoration: none;
  color: aqua;
  padding-bottom: 0.15em;
  box-sizing: border-box;
  box-shadow: inset 0 -0.2em 0 aqua;
  transition: 0.2s;
}

.underlined-a:hover {
  color: #222;
  box-shadow: inset 0 -2em 0 aqua;
  transition: all 0.45s cubic-bezier(0.86, 0, 0.07, 1);
}
<div>As inspired from the website of the <a href="https://www.airforce.com/" class="underlined-a">&nbsp;U.S. AirForce&nbsp;</a></div>
<br><br>
<a href="https://www.airforce.com/" class="brk-btn">
  Join Now
</a>
© www.soinside.com 2019 - 2024. All rights reserved.