CSS:鼠标移出时的过渡不透明?

前端之家收集整理的这篇文章主要介绍了CSS:鼠标移出时的过渡不透明?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
.item:hover {
        zoom: 1;
        filter: alpha(opacity=50);
        opacity: 0.5;
        -webkit-transition: opacity .15s ease-in-out;
        -moz-transition: opacity .15s ease-in-out;
        -ms-transition: opacity .15s ease-in-out;
        -o-transition: opacity .15s ease-in-out;
        transition: opacity .15s ease-in-out;
    }

为什么这只是动画的不透明度,当我悬停,但不是当我离开的对象与鼠标?

演示在这里:http://jsfiddle.net/7uR8z/

解决方法

您只将转换应用于:hover伪类,而不是元素本身。
.item {   
  height:200px;
  width:200px;
  background:red; 
  -webkit-transition: opacity 1s ease-in-out;
  -moz-transition: opacity 1s ease-in-out;
  -ms-transition: opacity 1s ease-in-out;
  -o-transition: opacity 1s ease-in-out;
  transition: opacity 1s ease-in-out;
}

.item:hover {
  zoom: 1;
  filter: alpha(opacity=50);
  opacity: 0.5;
}

演示:http://jsfiddle.net/7uR8z/6/

如果不希望转换影响鼠标悬停事件,而只想要鼠标悬停事件,则可以为:hover状态关闭转场:

.item:hover {
  -webkit-transition: none;
  -moz-transition: none;
  -ms-transition: none;
  -o-transition: none;
  transition: none;
  zoom: 1;
  filter: alpha(opacity=50);
  opacity: 0.5;
}

演示:http://jsfiddle.net/7uR8z/3/

猜你在找的CSS相关文章