我想要应用延迟鼠标出在css [英] I Want To Apply Delay On Mouse Out in css

查看:82
本文介绍了我想要应用延迟鼠标出在css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在鼠标输出事件开始CSS转换之前应用延迟。我的CSS代码如下,请让我知道如何在CSS转换之前应用时间延迟。

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.

我想实现在用户将鼠标指针移出菜单后,菜单保持稳定一段时间(例如3秒)。

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.

.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;
}


推荐答案

一个过渡,语法如下:

transition: all 0.5s ease-in-out 3s;

因此

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.

http://jsfiddle.net/pgqM2/

窍门是当没有悬停时,重新定义转换以添加3s延迟,但是当有悬停时具有0s延迟:

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:

li ul {
    opacity: 0;
    transition: all 0.5s ease 3s;
}

li:hover ul {
    opacity: 1;
    transition: all 0.5s ease 0s;
}

这篇关于我想要应用延迟鼠标出在css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆