CSS Webkit Transition - 比Fade in缓慢淡出

时间:2021-08-14 20:23:49

This is what I have:

这就是我所拥有的:

.box{
    background:#FFF;
    -webkit-transition: background 0.5s;
}

.box:hover{
    background:#000;
}

But this appends to both onmouseover and onmouseout actions, but isn't there a way to control them? Something like:

但这既适用于onmouseover,也适用于onmouseout行动,但是没有办法控制它们吗?就像是:

-wekbkit-transition-IN: background 1s;
-webkit-transition-OUT: background 10s;

2 个解决方案

#1


30  

Just redifine your transition in the over pseudo element.

只需在over伪元素中重新转换您的过渡。

.box{
    background: white;
    -webkit-transition: background 5s;
}
.box:hover{
    background: olive;
    -webkit-transition: background 1s;
}

Look my http://jsfiddle.net/DoubleYo/nY8U8/

看看我的http://jsfiddle.net/DoubleYo/nY8U8/

#2


0  

Either use an animation (only in webkit currently), or use JS to add and remove the properties, they will still animate.

要么使用动画(目前只在webkit中使用),要么使用JS添加和删除属性,它们仍然会生成动画。

#1


30  

Just redifine your transition in the over pseudo element.

只需在over伪元素中重新转换您的过渡。

.box{
    background: white;
    -webkit-transition: background 5s;
}
.box:hover{
    background: olive;
    -webkit-transition: background 1s;
}

Look my http://jsfiddle.net/DoubleYo/nY8U8/

看看我的http://jsfiddle.net/DoubleYo/nY8U8/

#2


0  

Either use an animation (only in webkit currently), or use JS to add and remove the properties, they will still animate.

要么使用动画(目前只在webkit中使用),要么使用JS添加和删除属性,它们仍然会生成动画。