CSS 退出时删除动画

标签 css css-animations

我有一个在悬停时从左向右删除的动画 here 。我想要一个从左到右的退出动画(而不是演示中所示的从右到左)。我怎样才能实现这个目标?

.btn {
  color: #31302B;
  background: #FFF;
  margin: 25px;
  padding: 10px 0;
  width: 240px;
  border: 3px solid #31302B;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 2px;
  display: inline-block;
  text-align: center;
  cursor: pointer;
  box-shadow: inset 0 0 0 0 #6a0dad;
  -webkit-transition: all ease 0.8s;
  -moz-transition: all ease 0.8s;
  transition: all ease 0.8s;
}

.btn:hover {
  box-shadow: inset 240px 0 0 0 #6a0dad;
  color: #fff;
}
<div class="btn">CONTAINER</div>

最佳答案

您可以使用@keyframes:

.btn {
  color: #31302B;
  background: #FFF;
  margin: 25px;
  padding: 10px 0;
  width: 240px;
  border: 3px solid #31302B;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 2px;
  display: inline-block;
  text-align: center;
  cursor: pointer;
  animation: out 0.8s ease;
}

@keyframes in {
  from {
    box-shadow: inset 0 0 0 0 #6a0dad;
    color: black;
  }
  to {
    box-shadow: inset 240px 0 0 0 #6a0dad;
    color: white;
  }
}

@keyframes out {
  from {
    box-shadow: inset -240px 0 0 0 #6a0dad;
    color: white;
  }
  to {
    box-shadow: inset 0 0 0 0 #6a0dad;
    color: black;
  }
}

.btn:hover {
  animation: in 0.8s ease;
  box-shadow: inset 240px 0 0 0 #6a0dad;
  color: white;
}
<div class="btn">CONTAINER</div>

关于CSS 退出时删除动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61866774/

相关文章:

html - 关键帧动画在不可见时也会渲染吗?它们会消耗资源吗?

jquery - CSS 动画可以处理淡入吗?

javascript - 添加 css 和 javascript 到 Yii 的 CHtml 和其他属性

javascript - 为什么我的动画会做我不期望的事情?

html - 在 HTML 元素中 float 的 CSS3 动画

css - float div 未扩展到 100%

css - 如何定义css动画?

javascript - Bootstrap - 在调整窗口大小时使用推拉但屏幕切断 div

javascript - jQuery 和 HTML - 点击当前 div 框 id 显示子 dvi 框内容

html - 输入类型数字的跨浏览器样式,使其长度不会超过必要的长度