【发布时间】:2015-04-16 03:29:03
【问题描述】:
我有一个菜单,我想使用 css3 对其进行动画处理。当您悬停主菜单时,我想在子菜单中滑动。但是我不知道将transition 属性放在哪里,以使其具有双向动画效果。
这是一个正常工作的示例,但仅在悬停时。
但它只是在我结束悬停时突然关闭,而不是向上滑动。
我尝试将transition 放在#sub 元素上,但没有任何反应。
这是css:
#main {
position: relative;
height: 110px;
width: 100%;
background-color: red;
}
#sub {
position: relative;
height: 100px;
width: 100%;
background-color: green;
margin-top: -100px;
z-index: -10;
//If transition is put here, nothing happens
}
#menu:hover > #sub {
margin-top: 0;
transition: margin-top 0.5s ease;
}
还有 HTML:
<nav>
<div id="menu">
<div id="main">MAINMENU</div>
<div id="sub">SUBMENU</div>
</div>
</nav>
【问题讨论】:
-
你确定你没有做错,错字或类似的事情吗?因为这个jsfiddle 工作正常,所以
transition: margin-top 0.5s ease;被放置在//If transition is put here, nothing happens -
@LongInt:正确的位置仅在
#sub上。如果您没有犯任何其他错误,它应该可以工作。 Here 是一个示例。 -
这对我不起作用。在最新的 Chrome、Windows 7 上。但它在 Firefox 和 IE 中确实有效....那么一定是 Chrome 的东西。
-
@LongInt:我正在使用最新的 Opera,它也使用 Webkit,所以我很惊讶它在 Chrome 上不起作用。
-
刚刚在 Windows 8.1 上签入了最新的 Chrome 版本(版本 42.0.2300.2 dev-m),它确实可以工作。
标签: html css transition