I am trying to apply a delay before starting a CSS transition on mouse out event. My CSS code is below, please let me know how to apply time delay before CSS transition on mouse out starts.
我试图在鼠标输出事件开始CSS转换之前应用延迟。我的CSS代码如下,请让我知道如何在鼠标输出开始CSS转换之前应用时间延迟。
I want to achieve that the menu stays stable for some time (e.g. for 3 seconds) after the user moves mouse pointer out of the menu.
我希望在用户将鼠标指针移出菜单后,菜单保持稳定一段时间(例如3秒)。
.timnav li .dropdown {
width: auto;
min-width: 0px;
max-width: 230px;
height: 0;
position: absolute;
overflow: hidden;
z-index: 999;
background:rgba(255, 255, 255, 0.8);
}
.timnav li:hover .dropdown {
min-height: 60px;
max-height: 500px;
height: auto;
width: 100%;
padding: 0;
-webkit-transition: delay .5s ease-in-out;
-moz-transition: delay .5s ease-in-out;
-o-transition: delay .5s ease-in-out;
}
.timnav li .dropdown ul {
margin: 0;
margin-top:7px;
}
.timnav li .dropdown ul > li {
display: block;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
padding-bottom:2px;
}
.timnav li .dropdown .dropdown2{
display: none;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
}
.timnav li .dropdown ul > li:hover .dropdown2{
display: block;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
}
.timnav li .dropdown .dropdown2:hover {
display: block;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
}
.timnav li .dropdown .dropdown2 li a {
display: block;
padding-left:7px !important;
height:6 !important;
padding-top:8px;
background: url(../images/nav-bg.jpg) repeat; color:#fff;
}
.timnav li .dropdown ul > li a {
display: block;
line-height: 26px;
height: 22px;
padding: 10px;
background: url(../images/nav-crrent.jpg) repeat; color:#FFFFFF;
}
.timnav ul .dropdown ul li:first-child a {
border-radius: 0;
}
.timnav li .dropdown li a:hover {
background: url(../images/nav-bg.jpg) repeat; color:#000;
}
4 个解决方案
#1
21
You can add a delay to a transition, the syntax is as follows:
您可以为转换添加延迟,语法如下:
transition: all 0.5s ease-in-out 3s;
So
transition: <property> <duration> <timing-function> <delay>;
The syntax is the same for all the prefixed versions also.
所有前缀版本的语法也相同。
I have created a demo of this, because you need to do something a bit tricky in order to make the item appear with no delay, but delay before it goes.
我已经创建了一个这样的演示,因为你需要做一些有点棘手的事情,以使项目没有延迟,但在它之前延迟。
The trick is to re-define the transition to add the 3s delay when there is no hover, but to have a 0s delay when there is a hover:
诀窍是重新定义转换,以便在没有悬停时添加3秒延迟,但在有悬停时有0秒延迟:
li ul {
opacity: 0;
transition: all 0.5s ease 3s;
}
li:hover ul {
opacity: 1;
transition: all 0.5s ease 0s;
}
#2
6
There is a transition-delay
property in CSS. Simply add this to your code, and you will get the desired effect.
CSS中有一个transition-delay属性。只需将其添加到您的代码中,您就可以获得所需的效果。
transition-delay:3s;
For the purpose of shorthand transition properties, here is a picture that sums it up
出于速记过渡属性的目的,这是一张总结它的图片
So in your case it would look like this
所以在你的情况下,它看起来像这样
div:hover {
-webkit-transition: .5s ease-in-out 3s;
-moz-transition: .5s ease-in-out 3s;
-o-transition: .5s ease-in-out 3s;
transition: .5s ease-in-out 3s;
color: red;
cursor: pointer;
}
<div>Hover me. There is a delay!</div>
Here is a fiddle to demonstrate
这是一个小提琴演示
#3
3
You cant use css transition when using display none, only solution with display none is js.
当使用display none时,你不能使用css转换,只有display none的解决方案是js。
#4
0
You can use the css3 property transition-delay to delay executing css. Click "Try it Yourself" to see an example.
您可以使用css3属性transition-delay来延迟执行css。点击“自己动手”查看示例。
#1
21
You can add a delay to a transition, the syntax is as follows:
您可以为转换添加延迟,语法如下:
transition: all 0.5s ease-in-out 3s;
So
transition: <property> <duration> <timing-function> <delay>;
The syntax is the same for all the prefixed versions also.
所有前缀版本的语法也相同。
I have created a demo of this, because you need to do something a bit tricky in order to make the item appear with no delay, but delay before it goes.
我已经创建了一个这样的演示,因为你需要做一些有点棘手的事情,以使项目没有延迟,但在它之前延迟。
The trick is to re-define the transition to add the 3s delay when there is no hover, but to have a 0s delay when there is a hover:
诀窍是重新定义转换,以便在没有悬停时添加3秒延迟,但在有悬停时有0秒延迟:
li ul {
opacity: 0;
transition: all 0.5s ease 3s;
}
li:hover ul {
opacity: 1;
transition: all 0.5s ease 0s;
}
#2
6
There is a transition-delay
property in CSS. Simply add this to your code, and you will get the desired effect.
CSS中有一个transition-delay属性。只需将其添加到您的代码中,您就可以获得所需的效果。
transition-delay:3s;
For the purpose of shorthand transition properties, here is a picture that sums it up
出于速记过渡属性的目的,这是一张总结它的图片
So in your case it would look like this
所以在你的情况下,它看起来像这样
div:hover {
-webkit-transition: .5s ease-in-out 3s;
-moz-transition: .5s ease-in-out 3s;
-o-transition: .5s ease-in-out 3s;
transition: .5s ease-in-out 3s;
color: red;
cursor: pointer;
}
<div>Hover me. There is a delay!</div>
Here is a fiddle to demonstrate
这是一个小提琴演示
#3
3
You cant use css transition when using display none, only solution with display none is js.
当使用display none时,你不能使用css转换,只有display none的解决方案是js。
#4
0
You can use the css3 property transition-delay to delay executing css. Click "Try it Yourself" to see an example.
您可以使用css3属性transition-delay来延迟执行css。点击“自己动手”查看示例。