.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; }
为什么当我将鼠标悬停在鼠标上时,为什么只在不透明度上设置动画呢?
您仅将转换应用于:hover伪类,而不应用于元素本身。
: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; }
如果您只希望过渡不影响mouse-over事件,mouse-out则可以为:hoverstate 关闭过渡:
mouse-over
mouse-out
.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; }