8

HTML:

 <div id="slick-slidetoggle">wxyz</div>           

            <div id="slickbox" >abcd</div>​

JS

// 一旦 DOM 准备好就隐藏 slickbox(页面加载稍早一点)

         var hoverVariable=false;
        var hoverVariable2=false;

        $('#slickbox').hide();
        $('#slick-slidetoggle').mouseover(function() {
            hoverVariable2=true;
            $('#slickbox').slideToggle(600);
            return false;
        })
        $('#slick-slidetoggle').mouseleave(function() {
            hoverVariable2=false;
            setTimeout(function (){
            if(!hoverVariable && !hoverVariable2){
            $('#slickbox').slideToggle(600);
            return false;}
         }, 1000);
        })
        $('#slickbox').mouseleave(function() {                    
            hoverVariable=false;
            setTimeout(function (){
            if(!hoverVariable && !hoverVariable2){                    
            $('#slickbox').slideToggle(600);
            return false;}
            return false;
           }, 1000); 
        })
        $('#slickbox').mouseover(function() {
             hoverVariable2=false;

            hoverVariable=true;

        })​

CSS

#slickbox {
    background: black;
    width:100px;
    height: 135px;
    display: none; 
    cursor:pointer;
    color:white;
}
#slick-slidetoggle{
 background: yellow;
    width:100px;
    height: 135px;
    cursor:pointer;
    color:black;

}

​</p>

现在上面的功能是我想要使用纯 CSS 实现的,即当我将鼠标悬停在“wxyz”按钮上时,“abcd”按钮应该下降并保持可见,即使鼠标从“wxyz”移开 3 秒。

我尝试了使用显示属性的转换延迟,但显然这不适用于显示属性,然后我尝试了位置:绝对和可见性以及可见性的转换延迟,但是按钮的出现延迟了 3 秒而不是隐藏。我希望“abcd”按钮在仅使用 CSS 或 CSS3 将按钮从“wxyz”移开 3 秒后隐藏

4

3 回答 3

3

这是一个示例(此处为代码

(我只写了-webkit,但你可以添加其他前缀)

#test2 {
    position:absolute;
    z-index:1;
    background: black;
    width:100px;
    height: 135px;
    opacity: 0; 
    cursor:pointer;
    color:white;
    opacity:0;
    -webkit-animation-duration: 600ms;
    -webkit-animation-timing-function: ease-in-out;
    -webkit-animation-iteration-count: 1;
    -webkit-animation-fill-mode: both;
}

#test {
    position:absolute;
    z-index:2;
    background: yellow;
    width:100px;
    height: 135px;
    cursor:pointer;
    color:black;

}
.container {
  position:relative;
}

.container:hover #test2 {
  opacity:1;
  -webkit-animation-name: slideDown;
}

.container:not(:hover) > #test2 {
  -webkit-animation-delay:1000ms;
  -webkit-animation-name: slideUp;
  opacity:1;
}

@-webkit-keyframes slideDown {
    0% {
        -webkit-transform: translateY(0);
    } 
    100% {
        -webkit-transform: translateY(135px);
    }
}

@-webkit-keyframes slideUp {
    0% {
        -webkit-transform: translateY(135px);
    } 
    100% {
        -webkit-transform: translateY(0);
    }
}
于 2012-12-31T09:20:14.740 回答
0

使用过渡执行如下操作:

    <head>
        <style>
            #outer {
                width: 100px;
                height: 50px;
                background-color: green;
                position: relative;
            }
            #innerOne {
                width: 100px;
                height: 50px;
                background-color: blue;
            }
            #innerTwo {
                width: 100px;
                height: 50px;
                background-color: red;
                position: absolute;
                top: -150px;
                left: 100px;

            }

            #outer:hover #innerTwo {
                top: 0px;

                -webkit-transition: top 2s ease-out;
                -moz-transition: top 2s ease-out;
                -o-transition: top 2s ease-out;
                transition: top 2s ease-out;
            }
            #innerTwo:not(hover) {
                -webkit-transition: top 1s ease-in 3s;
                -moz-transition: top 1s ease-in 3s;
                -o-transition: top 1s ease-in 3s;
                transition: top 1s ease-in 3s;
            }
        </style>
    </head>
    <body>
        <div id="outer">
            <div id="innerOne">wxyz</div>
            <div id="innerTwo">abcd</div>
        </div>
    </body>
</html>
于 2012-12-31T09:26:49.547 回答
0

这是一个跨浏览器的解决方案:

测试时间OPERA- SAFARI- CHROME- MAXTHON-FIREFOX

HTML:

<div class="container">
    <div id="test">wxyz</div>           
    <div id="test2" >abcd</div>
</div>

CSS:

#test {
    width:100px;
    height:100px;
    background:yellow;
    position:relative;
    z-index:2;
}
#test2 {
    top:-100px;
    width:100px;
    height:100px;
    background:black;
    color:white;
    position:relative;
    z-index:1;
}
.container:hover #test2 {
    top:0px;
    transition-property:top;
    transition-duration:0.2s;
    transition-timing-function: linear;
    /* Firefox 4 */
    -moz-transition-property:top;
    -moz-transition-duration:0.2s;
    -moz-transition-timing-function:linear;
    /* Safari and Chrome */
    -webkit-transition-property:top;
    -webkit-transition-duration:0.2s;
    -webkit-transition-timing-function:linear;
    /* Opera */
    -o-transition-property:top;
    -o-transition-duration:0.2s;
    -o-transition-timing-function:linear;
    /* IE */
    -ms-transition-property:top;
    -ms-transition-duration:0.2s;
    -ms-transition-timing-function:linear;
}
.container:not(:hover) #test2 {
    top:-100px;
    transition-property:top;
    transition-duration:0.2s;
    transition-timing-function: linear;
    transition-delay: 3s;
    /* Firefox 4 */
    -moz-transition-property:top;
    -moz-transition-duration:0.2s;
    -moz-transition-timing-function:linear;
    -moz-transition-delay:3s;
    /* Safari and Chrome */
    -webkit-transition-property:top;
    -webkit-transition-duration:0.2s;
    -webkit-transition-timing-function:linear;
    -webkit-transition-delay:3s;
    /* Opera */
    -o-transition-property:top;
    -o-transition-duration:0.2s;
    -o-transition-timing-function:linear;
    -o-transition-delay:3s;
    /* IE */
    -ms-transition-property:top;
    -ms-transition-duration:0.2s;
    -ms-transition-timing-function:linear;
    -ms-transition-delay:3s;
}

小提琴:http: //jsfiddle.net/BerkerYuceer/2gVLX/

于 2012-12-31T10:03:03.150 回答