CSS 使用 CSS3 过渡延迟鼠标移开/悬停
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9393125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delay mouseout/hover with CSS3 transitions
提问by patad
I've got a box that changes size when being hovered. However, I would like to delay the mouseout stage, so that the box keep the new size for a few seconds, before getting the old size back.
我有一个在悬停时会改变大小的框。但是,我想延迟 mouseout 阶段,以便框保持新大小几秒钟,然后再取回旧大小。
div {
width: 70px;
-webkit-transition: .5s all;
}
div:hover {
width:130px;
}
Is this possible to do WITHOUT Javascript and only CSS3? I only have to care about supporting webkit.
这是否可以在没有 Javascript 和只有 CSS3 的情况下完成?我只需要关心支持webkit。
回答by patad
div {
width: 70px;
-webkit-transition: .5s all;
-webkit-transition-delay: 5s;
-moz-transition: .5s all;
-moz-transition-delay: 5s;
-ms-transition: .5s all;
-ms-transition-delay: 5s;
-o-transition: .5s all;
-o-transition-delay: 5s;
transition: .5s all;
transition-delay: 5s;
}
div:hover {
width:130px;
-webkit-transition-delay: 0s;
-moz-transition-delay: 0s;
-ms-transition-delay: 0s;
-o-transition-delay: 0s;
transition-delay: 0s;
}
This will trigger the mouseover state right away, but wait 5 sec till the mouseout is triggered.
这将立即触发鼠标悬停状态,但要等待 5 秒直到触发鼠标悬停。
回答by Jenny
transition can be declared as
过渡可以声明为
transition: .5s all 5s
(shorthand, the first number is duration, the second number is delay) then you don't need the separate transition-delay
(简写,第一个数字是持续时间,第二个数字是延迟)那么你不需要单独的转换延迟
sorry, can't add as a comment as I don't have enough points
抱歉,无法添加评论,因为我没有足够的积分