Reputation: 2764
Is there a way to use -webkit-transition
with display
?
I'm using CSS display
to hide and show a navigations second level … but only display: none
and display: block
on :hover
is a little un-sexy… a ease
would be great (like -webkit-transition: display 300ms ease-in;
)
I know that's fairly easy to do this with jQuery, but I'm currently trying to setup everything with CSS3 (i know: not all browsers do support it, but that's irrelevant for this one project I'm currently working on)
here's some code & structure: (the li.menu1
has a :hover
with section.nav-menu1 {display: block;}
)
<ul>
<li class="menu1"><a href="#">Menu 1</a>
<section class="nav-menu1">
<h1 class="none">Level 2 Overlay</h1>
<nav>
<h2 class="none">Menu 1 Navigation</h2>
<ul>
<li><a href="#">Menu 1 Level 2-1</a></li>
<li><a href="#">Menu 1 Level 2-2</a></li>
<li><a href="#">Menu 1 Level 2-3</a></li>
</ul>
</nav>
</section>
</li>
</ul>
Upvotes: 19
Views: 47185
Reputation: 1
Use overflow:hidden > overflow:visible
, works better, I use like this:
example {
#menu ul li ul {
background-color:#fe1c1c;
width:85px;
height:0px;
opacity:0;
box-shadow:1px 3px 10px #000000;
border-radius:3px;
z-index:1;
-webkit-transition:all 0.5s ease;
-moz-transition:all 0.6s ease;
}
#menu ul li:hover ul {
overflow:visible;
opacity:1;
height:140px;
}
is better than visible because overflow:hidden
act exactly like a display:none
,
Upvotes: -2
Reputation: 17812
So I'm not sure I see all the pieces put together here. You want to animate opacity and visibility, with visibility having a delay so opacity is done before it triggers;
opacity: 0;
-moz-transition: opacity .25s linear, visibility .1s linear .5s;
-webkit-transition: opacity .25s linear, visibility .1s linear .5s;
-o-transition: opacity .25s linear, visibility .1s linear .5s;
transition: opacity .25s linear, visibility .1s linear .5s;
visibility: hidden;
to
opacity: 1;
visibility: visible;
visibility will wait .5s and then switch over to hidden. You can even turn off the visibility transition on one side if you want it to fade both ways. (So that when fading in, the element is instantly visible instead of waiting .5s and transitioning.)
Upvotes: 18
Reputation: 12156
You should use height
or width
transition in order to show and hide second level menu. Display
property is not supported by transitions.
There is an article at ODC with something similar to your needs. Also, I've modified it a bit in order to look more like menu item. Works perfect in Opera 10.7, without transitions in Firefox 3.6.12 and doesn't at all in Chrome 7.0.517.41.
I hope this will be useful as start point for your own animated menu.
Update 1:
Your menu with ease-in transitions. Probably, I've got something wrong about it's structure. The problem is that transitions do not work with auto
, so you have to manually specify final height.
Update 2: Use opacity as transition property. On invisible element set visibility:hidden and visibility:visible on visible. That will prevent from invisible clickable links. Also, visible-invisible transition doesn't work, don't know why. Have to work more om it.
Upvotes: 13
Reputation: 31750
You should use an opacity transition, not a display transition for this. Display:none removes an element from the layout entirely - I think you want it there, but invisible.
Upvotes: 0