【问题标题】:How to retain unhover state style on hover state after a delay in my css style在我的 CSS 样式延迟后,如何在悬停状态下保留悬停状态样式
【发布时间】:2017-03-20 08:31:11
【问题描述】:

我正在尝试定义 css 样式,其中当悬停元素时,不透明度应从 0 变为 1。如果未发生悬停,几秒钟后不透明度应将其值更改为 0。

.selection:hover .player-icon {
    opacity: 1;

  transition-duration: 3s;
    -moz-transition: opacity .25s ease-in;
    -webkit-transition: opacity .25s ease-in;
    -o-transition: opacity .25s ease-in;*/
}

.player-icon {
    margin-left: 45%;
    margin-top: 21%;
    z-index: 999;
    position: absolute;
    width: 55px;
    height: 55px;
 opacity: 0;
   transition: opacity .5s ease-out;
 -moz-transition: opacity .5s ease-out;
    -webkit-transition: opacity .5s ease-out;
    -o-transition: opacity .5s ease-out;
}

【问题讨论】:

  • 您需要为此使用 JavaScript。如果特定时间已过,则在元素上添加一个类并覆盖悬停样式。

标签: css hover transition


【解决方案1】:

使用keyframe animation。

@keyframes show-hide {
  0%   { color: red; }
  10% { color: white; }
  90% { color: white;}
  100% { color: red; }
}

.player-icon {
  display: inline-block;
  padding: 1em;
  color: red;
  background-color: red;
}

.player-icon:hover {
  animation: show-hide 3s linear;
}
Put your cursor on the red rectangle more than 3 seconds.<br><br>
<div class="player-icon">Play</div>

【讨论】:

    猜你喜欢
    • 2018-12-19
    • 2013-01-14
    • 2013-01-24
    • 2013-03-28
    • 2013-01-08
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    相关资源
    最近更新 更多