【问题标题】:CSS 3 Animation with Keyframes on hover change of opacity and z-index don't workCSS 3 Animation with Keyframes on hover change of opacity and z-index不起作用
【发布时间】:2016-07-28 22:01:19
【问题描述】:

我有一些动人的文字css3动画。 动画很好(sn-p)。如果有人使用悬停,动画会停止(很好),但不接受不透明度和 z-index 的更改(.bubble:hover)。

    opacity: 1;
    z-index: 100;

.bubble:hover 类正在使用中,转换动作有效。

transform: scale(1.2);

目的是在前景中弹出悬停的气泡。 如果气泡离开,动画应该从停止点继续移动。 我该如何解决?

感谢您的帮助。

.solSystem {
  postion: absolute;
  height: 25vw;
}
.orbitLink,
.orbitLink:active,
.orbitLink:visited {
  color: #FFF;
}
.mars:hover,
.earth:hover {
  animation-play-state: paused;
}
.bubble:hover {
  background: #DE383B !Important;
  padding: 1vw;
  border: 0.1vw solid #000;
  color: #FFF !Important;
  transform: scale(1.2);
  opacity: 1;
  z-index: 100;
}
.mars {
  float: left;
  margin: 4vw auto;
  border-radius: 50%;
  position: absolute;
  animation-name: moveRigthToLeft, scale, color;
  animation-iteration-count: infinite, infinite;
  animation-timing-function: ease-in-out, linear;
}
.earth {
  float: left;
  margin: 4vw auto;
  border-radius: 50%;
  position: absolute;
  animation-name: moveLeftToRigth, scale, color;
  animation-iteration-count: infinite, infinite;
  animation-timing-function: ease-in-out, linear;
}
.bubble {
  padding: 1vw;
  color: #FFF;
  border-color: #000;
  border-width: 0.1vw;
  background-color: #004A99;
  font-weight: bold;
  font-size: 1.1vw;
  font-family: Arial, FreeSans, sans-serif;
  position: absolute;
  border-style: solid;
  border-radius: 100%;
}
@keyframes moveLeftToRigth {
  0% {
    left: 15vw;
  }
  50% {
    left: 40vw;
  }
  100% {
    left: 15vw;
  }
}
@keyframes scale {
  0% {
    transform: scale(1);
  }
  32% {
    transform: scale(0.7);
    animation-timing-function: ease-in;
  }
  70% {
    transform: scale(0.8);
    animation-timing-function: ease-in;
  }
  75% {
    transform: scale(0.9);
    animation-timing-function: ease-in-out;
  }
  86% {
    transform: scale(1.2);
  }
  98% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes color {
  0% {
    opacity: 0.5;
    z-index: 1;
  }
  20% {
    opacity: 0.6;
    z-index: 2;
  }
  40% {
    opacity: 0.7;
    z-index: 3;
  }
  60% {
    opacity: 0.8;
    z-index: 4;
  }
  80% {
    opacity: 0.9;
    z-index: 5;
  }
  90% {
    opacity: 1;
    z-index: 6;
  }
  95% {
    opacity: 0.8;
    z-index: 4;
  }
  100% {
    opacity: 0.6;
    z-index: 2;
  }
}
<div class="solSystem">
  <a href="Test1.html">
    <div class="earth" style="animation-duration: 20s,20s,20s;">
      <div class="bubble" style="left:12vw;">
        <a href="Test1.html" title="Test1" class="orbitLink"> Test1</a>
      </div>
    </div>
  </a>
  <a href="Test2.html">
    <div class="mars" style="animation-duration: 30s,30s,30s;">
      <div class="bubble" style="left:30vw;">
        <a href="Test2.html" title="Test2" class="orbitLink">Test2</a> 
      </div>
    </div>
  </a>
</div>

【问题讨论】:

  • !important 不起作用?
  • !important 不起作用

标签: html css css-animations


【解决方案1】:

这发生的原因是您使用“颜色”关键帧为父 div 提供了较少的不透明度,然后将该动画应用于悬停 div 的父级。您应该对“气泡”div 进行颜色更改。

代码笔: http://codepen.io/bra1N/pen/dXKLbp

.solSystem {
  postion: absolute;
  height: 25vw;
}
.orbitLink,
.orbitLink:active,
.orbitLink:visited {
  color: #FFF;
}
.mars:hover,
.earth:hover {
  animation-play-state: paused;
}/*
.bubble:hover {
  background: #DE383B !Important;
  padding: 1vw;
  border: 0.1vw solid #000;
  color: #FFF !Important;
  transform: scale(1.2);
  opacity: 1 !important;
  z-index: 100 !important;
}*/
.mars {
  float: left;
  margin: 4vw auto;
  border-radius: 50%;
  position: absolute;
  animation-name: moveRigthToLeft, scale;
  animation-iteration-count: infinite, infinite;
  animation-timing-function: ease-in-out, linear;
}
.earth {
  float: left;
  margin: 4vw auto;
  border-radius: 50%;
  position: absolute;
  animation-name: moveLeftToRigth, scale;
  animation-iteration-count: infinite, infinite;
  animation-timing-function: ease-in-out, linear;
}
.bubble {
  padding: 1vw;
  color: #FFF;
  border-color: #000;
  border-width: 0.1vw;
  background-color: #004A99;
  font-weight: bold;
  font-size: 1.1vw;
  font-family: Arial, FreeSans, sans-serif;
  position: absolute;
  border-style: solid;
  border-radius: 100%;
  animation-name: color;
  animation-iteration-count: infinite;
  animation-duration: 30s;
}
@keyframes moveLeftToRigth {
  0% {
    left: 15vw;
  }
  50% {
    left: 40vw;
  }
  100% {
    left: 15vw;
  }
}
@keyframes scale {
  0% {
    transform: scale(1);
  }
  32% {
    transform: scale(0.7);
    animation-timing-function: ease-in;
  }
  70% {
    transform: scale(0.8);
    animation-timing-function: ease-in;
  }
  75% {
    transform: scale(0.9);
    animation-timing-function: ease-in-out;
  }
  86% {
    transform: scale(1.2);
  }
  98% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes color {
  0% {
    opacity: 0.4;
    z-index: 1;
  }
  20% {
    opacity: 0.6;
    z-index: 2;
  }
  40% {
    opacity: 0.7;
    z-index: 3;
  }
  60% {
    opacity: 0.8;
    z-index: 4;
  }
  80% {
    opacity: 0.9;
    z-index: 5;
  }
  90% {
    opacity: 1;
    z-index: 6;
  }
  95% {
    opacity: 0.8;
    z-index: 4;
  }
  100% {
    opacity: 0.6;
    z-index: 2;
  }
}
<div class="solSystem">
  <a href="Test1.html">
    <div class="earth" style="animation-duration: 20s,20s,20s;">
      <div class="bubble" style="left:12vw;">
        <a href="Test1.html" title="Test1" class="orbitLink"> Test1</a>
      </div>
    </div>
  </a>
  <a href="Test2.html">
    <div class="mars" style="animation-duration: 30s,30s,30s;">
      <div class="bubble" style="left:30vw;">
        <a href="Test2.html" title="Test2" class="orbitLink">Test2</a> 
      </div>
    </div>
  </a>
</div>

【讨论】:

  • 感谢您的回答,但在 chrome 和 opera 上不进行不透明度更改。 Z 指数没问题。在 FF 中它可以工作。
猜你喜欢
  • 1970-01-01
  • 2022-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-10
  • 2013-06-11
  • 1970-01-01
  • 2017-11-28
相关资源
最近更新 更多