我的问题是:
当用户将鼠标悬停在其父容器上时,我希望菜单淡入和淡出可见性。我也想用css做动画。这是代码:
HTML
<div class="color-dropdown">
<div class="title">
<h4>Red</h4>
</div>
<div class="options">
<ul class="colors">
<li>Red</li>
<li>Blue</li>
</ul>
</div>
</div>
SCSS
.color-dropdown {
height: 60px;
overflow: hidden;
.options {
opacity: 0;
/*
The problem - This css transition never
gets seen on mouseout, most likely because
overflow is immediately hidden.
*/
transition: opacity 0.2s linear;
}
&.expanded {
overflow: visible;
.options {
opacity: 1;
}
}
}
的CoffeeScript
colorDropdown = $('.color-dropdown')
title = $('.title h4')
colors = $('.colors li')
colorDropdown.hover ->
# Fade in the options
colorDropdown.addClass 'expanded'
, ->
# Fade out - Broken!
colorDropdown.removeClass 'expanded'
colors.click ->
# Fade out - Broken!
colorDropdown.removeClass 'expanded'
# Change the current color
title.text $(this).text()
# CSS bounce animation (using animate.css here)
title.addClass 'animated bounce'
setTimeout ->
title.removeClass 'animated bounce'
, 1000
I've made a jsfiddle here so that you can easily see the problem
提前致谢!
答案 0 :(得分:3)
问题在于您overflow: hidden
&lt; - &gt; overflow: visible
更改...当您移除.expanded
时,如果父级上的溢出跳回隐藏状态,您将看不到子级的转换。
您可以使用子级visibility
元素.options
上的转换来解决此问题。
这样的事情(transition-delay
设置为0s
)或许:
.color-dropdown {
height: 60px;
overflow: visible;
.options {
opacity: 0;
visibility:hidden;
transition: visibility 0s linear 0.2s, opacity 0.2s linear;
}
&.expanded .options {
opacity: 1;
visibility:visible;
transition-delay: 0s;
}
}
有关详细信息,请访问:http://www.greywyvern.com/?post=337