html - 链接悬停动画问题(骑士动画)

标签 html css css-animations keyframe

我创建了悬停在链接上的动画。

我使用进出关键帧创建了动画。

但是我遇到了问题。我认为这是因为骑士骑士动画。但我需要那个鼠标离开。

问题是页面加载时自动运行。码笔link

.container {
  padding: 50px;
  max-width: 500px;
}

.dashBottom {
  padding-left: 0px;
  position: relative;
  padding-bottom: 15px;
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  -ms-transition: all 0.3s;
  -o-transition: all 0.3s;
  transition: all 0.3s;
  color: black;
  text-decoration: none;
}
.dashBottom:after {
  position: absolute;
  content: "";
  bottom: 0px;
  width: 30px;
  background-color: black;
  height: 4px;
  left: 0;
  right: auto;
  -webkit-animation: knight-rider-out 0.5s;
  animation: knight-rider-out 0.5s;
  animation-fill-mode: forwards;
}
.dashBottom:hover:after {
  -webkit-animation: knight-rider-in 0.5s;
  animation: knight-rider-in 0.5s;
  animation-fill-mode: forwards;
}

@keyframes knight-rider-in {
  from {
    left: 0px;
    width: 30px;
  }
  50% {
    left: 0px;
    width: 100%;
  }
  to {
    left: calc( 100% - 30px);
    width: 30px;
  }
}
@keyframes knight-rider-out {
  from {
    left: calc( 100% - 30px);
    width: 30px;
  }
  50% {
    left: 0px;
    width: 100%;
  }
  to {
    left: 0px;
    width: 30px;
  }
}
<div class="container">
    <a class="viewMore dashBottom" href="#">View More</a>
</div>

最佳答案

为避免这种情况,您可以考虑过渡。这是用更少的代码实现相同效果的另一种方法:

.container {
  padding: 50px;
  max-width: 500px;
}

.dashBottom {
  padding-left: 0px;
  position: relative;
  padding-bottom: 15px;
  transition: all 0.3s;
  color: black;
  text-decoration: none;
  background-image:linear-gradient(#000,#000);
  background-size: 200% 4px;
  background-position: calc(200% + 30px) 100%;
  background-repeat:no-repeat;
  transition:0.5s all;
}

.dashBottom:hover {
  background-position:calc(-100% - 30px)  100%;
}
<div class="container">
    <a class="viewMore dashBottom" href="#">View More</a>
</div>

关于html - 链接悬停动画问题(骑士动画),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51098193/

相关文章:

javascript - 过滤json数据并将结果显示在表格中

css - Flex box child 的高度是 parent 的 100%

html - 在 Firefox 中删除 input[type=color] 中颜色周围的边框?

html - css3 动画不适用于图像

css3 文本动画持续时间问题

html - 将输入字段标记为无效

html - 我如何将视差图像的宽度扩展到全宽和全高

javascript - -webkit-box-shadow 无法使用 javascript 正确更改

javascript - 增加 png 图像的背景大小而不缩放图像

CSS3 - 动画延迟不起作用