html - CSS 动画。悬停状态在动画前闪烁

标签 html css css-animations

<分区>

我终于有了这个与我的设计师想出的原型(prototype)相匹配的动画,除了一件事,悬停状态会在动画播放之前闪烁。查看我的 CodePen:http://codepen.io/sinrise/pen/rxvjyx/

<style type="text/css">
@keyframes bounceInUp {
  from, 60%, 75%, to {
    -webkit-animation-timing-function: cubic-bezier(0.8, 0.6, 0.5, 1.000);
    animation-timing-function: cubic-bezier(0.8, 0.6, 0.5, 1.000);
  }

  from {
    -webkit-transform: translate3d(0, 390px, 0);
    transform: translate3d(0, 390px, 0);
  }

  60% {
    -webkit-transform: translate3d(0, -5px, 0);
    transform: translate3d(0, -5px, 0);
  }

  75% {
    -webkit-transform: translate3d(0, 1px, 0);
    transform: translate3d(0, 1px, 0);
  }

  to {
    opacity: 1;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}

.small-hero {
    position: relative;
    width: 100%;
    max-height: 385px;
    min-height: 385px;
    overflow-y: hidden;
    margin-bottom: 15px;
}
.small-hero::before {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(0,0,0,0.0), rgba(0,0,0,0.6));
    content: "";
}
.small-hero h3, .small-hero p, .small-hero a {
    position: absolute;
    top: 0;
    margin: 0 auto;
    color: #fff;
    z-index: 1;
    text-align: center;
}
.small-hero img { width: 100%; }
.small-hero .small-hero-hover-bg {
    position: absolute;
    top: 390px;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba($tmi-orange, 0.8);
    z-index: 2;
}
.small-hero .small-hero-hover-h3, .small-hero .small-hero-hover-p, .small-hero .small-hero-hover-a {
    position: absolute;
    top: 390px;
    z-index: 2;
    left: 0;
    right: 0;
    max-width: 500px;
    text-shadow: 2px 2px 10px rgba(0,0,0,0.5);
}
.small-hero .small-hero-hover-a { max-width: 200px; }
.small-hero .small-hero-hover-p { font-size: 18px; }
.small-hero:hover .small-hero-hover-bg {
    top: 0;
    transition: top 0.4s, opacity 0.4s;
}
.small-hero:hover .small-hero-hover-h3, .small-hero:hover .small-hero-hover-p, .small-hero:hover .small-hero-hover-a {
    animation: bounceInUp 0.5s 1;
}
.small-hero:hover .small-hero-hover-h3 {
    top: 100px;
}
.small-hero:hover .small-hero-hover-p {
    top: 150px;
    animation-delay: 0.05s;
}
.small-hero:hover .small-hero-hover-a {
    top: 250px;
    animation-delay: 0.1s;
}
</style>
<div class="small-hero">
  <img src="http://placehold.it/500x350" />
  <div class="small-hero-hover-bg"></div>
  <h3>Title</h3>
  <h3 class="small-hero-hover-h3">Title</h3>
  <p class="small-hero-hover-p">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis elit nec nisl imperdiet efficitur. Ut ut mauris non sapien elementum tempor.</p>
  <a href="#" class="small-hero-hover-a btn btn-action">Get a Quote</a>
</div>

最佳答案

http://codepen.io/anon/pen/rxvjQW

.small-hero h3, .small-hero p, .small-hero a 上用 opacity:0; 修复了

动画:bounceInUp 0.5s 1 forwards;悬停。

forwards 使您的元素将停留在动画的最后一帧。 opacity:0;让它以 0 不透明度开始。

Here是关于animation-fill-mode 的一些文档

关于html - CSS 动画。悬停状态在动画前闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35050262/

相关文章:

javascript - 设置 ScrollMagic 插件

javascript - 将多页 pdf 嵌入到网站中,用户可以在页面之间翻转 + 其他功能

javascript - 如何使用 jquery 通过 ID 删除多个 href 链接?

javascript - css 中的关键帧无法使用 javascript 正常工作

javascript - ng-show/hide 延迟图像动画

javascript - Return False 不适用于表格

javascript - 更改单选按钮检查的值的字体粗细

javascript - 使输入转到 div 的底部

python - 如何在 PyQt5 中自定义 QGroupBox 标题?

css - 使用 css 对进入中心图形然后环绕中心图形进行动画处理