悬停时的slideDown行为,内部div是绝对的

时间:2013-03-12 11:52:54

标签: jquery

这是我无法弄清楚的事情。

以下是一个简单示例:http://jsfiddle.net/MrkMZ/

HTML:

<div id="box">
    <div id="top"><a href="#">top text</a></div>
    <div id="bottom"><a href="#">bottom text</a></div>
</div>

CSS:

#box {
    width: 200px;
    height: 200px;
    background-color: yellow;
    position: relative;
}
#top {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 50px;
    background-color: #ff0000;
}
#top a {
    margin-top: 20px;
    display: inline-block;
}
#bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 200px;
    height: 30px;
    background-color: #ff0000;
}

JS:

$('#box').hover(
    function(){
        $(this).find('#top, #bottom').slideUp(300);
    },
    function(){
        $(this).find('#top, #bottom').slideDown(300);
    }
);

正如您所看到的,在框上悬停时,顶部和底部div正确滑动,但滑动时顶部和底部div内的文本表现不同。顶部文本保留,而底部文本向下滑动div。

无论如何要使顶部文字滑动?或者让底部文字留下而不是滑动。

在slideDown / slideUp上,jQuery会更改元素的高度。

唯一的区别是一个有顶部:0和底部有一个底部:0。这就是这种奇怪的效果。

我在这里缺少什么?

1 个答案:

答案 0 :(得分:-1)

我已经更新了您的小提琴,我想这就是您要找的内容,我为margin-top:30px代码http://jsfiddle.net/MrkMZ/1/

a做了{{1}}
相关问题