0

如何制作像 dabblet 这样的导航栏,在悬停时会下降?

http://sampsonblog.com/289/of-dice-dabblet-and-css

请注意,当您将鼠标悬停在“全部”上时,它似乎会从页面顶部下拉。我知道可以通过使两个具有 css 绝对位置的 div 来适当地定位“所有”和“内容”:

<div id="content">-All content that would come with the dropdown here/div>
<div id="all">All</div>

然后使用jquery附加悬停事件以动画“all”并使用动画使“all”和“content”css下拉(我有两个更新两个单独的dom元素的位置)。有没有更好的方法在 dom 中构造它,并且可能只使用 CSS3 来完成这个而不是描述和/或更好的方法来构造 dom,这样我就不必同时更新内容的位置和所有内容?

4

1 回答 1

1

我肯定不会用 javascript 或 jQuery 来做,因为只有 CSS3 才有可能

这里是一个例子或查看小提琴http://jsfiddle.net/mpaas/

#naviWrapper {
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;

    position:absolute;
    top:-200px;
    height:200px;
    left:0px;
    right:0px;
    background:#ccc;
}

#naviWrapper:hover {
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;

    top:0px;
}

#naviButton {
    position:absolute;
    bottom:-60px;
    left:50%;
    margin-left:-50px;
    width:100px;
    height:60px;
    background:#000;
    color:#fff;
    text-align:center;
}


<div id="naviWrapper">

    <div id="naviButton">Hover!</div>

</div>

这是可行的,因为按钮元素是包装器的子元素,因此在悬停 naviButton 时,它将调用包装器元素上的悬停,它通过在 css 样式顶部给出的查询进行动画处理。

于 2013-07-04T06:11:09.177 回答