html - 使用 CSS 从右到左 div 并在 5 秒后隐藏

标签 html css css-animations

我从右到左显示 div,5 秒后它将隐藏。我尝试了一些从右到左的代码可以工作,但 5 秒后它没有隐藏。

我在关键帧内尝试了 opacity:0 但我的动画不起作用。

你能帮我解决这个问题吗?

.successAlet {
  background-color: red;
  color: #fff;
  position: fixed;
  top: 0;
  width: 400px;
  right: 0;
  z-index: 1001;
  -webkit-animation-name: fadeInRight;
  animation-name: fadeInRight;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

@-webkit-keyframes fadeInRight {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(100%, 0, 0);
    transform: translate3d(100%, 0, 0);
  }
  100% {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
  }
}

@keyframes fadeInRight {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(100%, 0, 0);
    transform: translate3d(100%, 0, 0);
  }
  100% {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
  }
}
<div class="successAlet">
  <h2>Animate and then autohide in 5 sec</h2>
</div>

最佳答案

考虑第二个动画。您还可以通过删除大量不需要的属性来简化代码

.successAlet {
  background-color: red;
  color: #fff;
  position: fixed;
  top: 0;
  width: 400px;
  right: 0;
  z-index: 1001;
  animation-name: fadeInRight,hide;
  animation-duration: 1s;
  animation-delay: 0s,3s;
  animation-fill-mode: both;
}



@keyframes fadeInRight {
  0% {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }
}

@keyframes hide {
  100% {
    opacity: 0;
  }
}
<div class="successAlet">
  <h2>Animate and then autohide in 5 sec</h2>
</div>

关于html - 使用 CSS 从右到左 div 并在 5 秒后隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58247276/

相关文章:

jquery - Bootstrap 对话框 : Animate size changes

html - 响应式 html 表格链接在 iPad 上不起作用

html - Bootstrap - 选择和按钮在一行中彼此相邻

php - 无法正确获取边距

html - html css中的关键帧动画不起作用

html - Safari 中的 CSS 动画

html - CSS 不随 Django 更新

javascript - 我如何随机显示我的问题,使其现在始终相同? (JavaScript)

php - 如何在 Admin Silverstripe 中添加自定义按钮及其功能?

jquery - css 动画,动画名称,smoothstate.js