【问题标题】:Handling mouseout css effect处理 mouseout css 效果
【发布时间】:2014-11-21 11:29:12
【问题描述】:
.box {
  position: relative;
  background-color: #fe0000;
  height: 250px;
  width: 250px;
  border-radius: 3px;
  overflow: hidden;
  -moz-border-radius-bottomright: 138.88889px;
  -webkit-border-bottom-right-radius: 138.88889px;
  border-bottom-right-radius: 138.88889px;
  -moz-border-radius-bottomleft: 138.88889px;
  -webkit-border-bottom-left-radius: 138.88889px;
  border-bottom-left-radius: 138.88889px;
}
.box .shine {
  position: absolute;
  top: -200%;
  left: -200%;
  width: 500px;
  height: 500px;
  opacity: 0;
  background: rgba(255, 255, 255, 0.2);
  background: -moz-linear-gradient(left, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0.2)), color-stop(75%, rgba(255, 255, 255, 0.2)), color-stop(90%, rgba(255, 255, 255, 0.8)), color-stop(100%, rgba(255, 255, 255, 0)));
  background: -o-linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  background: -ms-linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, 6 rgba(255, 255, 255, 0) 100%);
  background: linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  transform: rotate(30deg);
  transition-property: left, top, opacity;
  transition-duration: 0.5s, 0.5s, 0.1s;
  transition-timing-function: ease-in-out;
}
.box:hover .shine {
  opacity: 1;
  top: -50%;
  left: -50%;
}

http://jsfiddle.net/iaezzy/0ad7pthm/

发光效果看起来不错,但是如果您将鼠标从元素上移开,就会出现奇怪的故障。如何控制鼠标移出行为?

【问题讨论】:

  • 你给它的小提琴在 Firefox v32.0.2 中运行良好

标签: css effect mouseout


【解决方案1】:

您无法通过 CSS 控制 mouseout 属性,但您可以通过从 transition-property 中删除 opacity 来消除该故障:

transition-property: left, top;

body {
  background: #444;
}

.box {
  position: relative;
  background-color: #fe0000;
  height: 250px;
  width: 250px;
  border-radius: 3px;
  overflow: hidden;
  -moz-border-radius-bottomright: 138.88889px;
  -webkit-border-bottom-right-radius: 138.88889px;
  border-bottom-right-radius: 138.88889px;
  -moz-border-radius-bottomleft: 138.88889px;
  -webkit-border-bottom-left-radius: 138.88889px;
  border-bottom-left-radius: 138.88889px;
}
.box .shine {
  position: absolute;
  top: -200%;
  left: -200%;
  width: 500px;
  height: 500px;
  opacity: 0;
  background: rgba(255, 255, 255, 0.2);
  background: -moz-linear-gradient(left, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0.2)), color-stop(75%, rgba(255, 255, 255, 0.2)), color-stop(90%, rgba(255, 255, 255, 0.8)), color-stop(100%, rgba(255, 255, 255, 0)));
  background: -o-linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  background: -ms-linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, 6 rgba(255, 255, 255, 0) 100%);
  background: linear-gradient(top, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.1) 75%, rgba(255, 255, 255, 0.5) 90%, rgba(255, 255, 255, 0) 100%);
  transform: rotate(30deg);
  transition-property: left, top;
  transition-duration: 0.5s, 0.5s, 0.1s;
  transition-timing-function: ease-in-out;
}
.box:hover .shine {
  opacity: 1;
  top: -50%;
  left: -50%;
}
<div class="box">
  <div class="shine"></div>
</div>

【讨论】:

  • 啊酷,另一个烦人的事情是,直到你将鼠标悬停在元素上,它会增加不透明度,使红色变得不那么亮。我只是想让光芒穿过它然后消失。
  • 我不确定你是否可以,它们是渐变,这是它的工作原理
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-19
  • 1970-01-01
相关资源
最近更新 更多