-webkit-transition with display
Solution 1
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.
Solution 2
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.)
Related videos on Youtube
albuvee
Updated on July 10, 2020Comments
-
albuvee over 3 years
Is there a way to use
-webkit-transition
withdisplay
?I'm using CSS
display
to hide and show a navigations second level … but onlydisplay: none
anddisplay: block
on:hover
is a little un-sexy… aease
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
withsection.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>
-
albuvee almost 13 yearshmm, if i use opacity, there are major problem with the :hover (because the element is there but invisible, therefore :hover'able/clickable) :-/
-
albuvee almost 13 yearsYEAH! Thx! … on hidden: <visibility:hidden; opacity: 0; -XY-transition: opacity 150ms ease-in;> and on the visible: <visibility: visible; opacity: 1; overflow: hidden;> … Thx!
-
fregante almost 13 yearsThe only keywords that work are colors. center, left, right, auto, etc are not transitioned (yet, I'd add) unfortunately.
-
alirobe about 12 yearsFades in great, but unfortunately the fade out doesn't work with this.
-
Claude over 11 yearsIf you want to fade both out and in, you can use the workaround in this gist: gist.github.com/2933815
-
Mark about 11 yearsFirst: please correct your code, its invalid. Second: overflow is not supported as transition.
-
Mike almost 11 yearsIt should be noted that if you want this to work on an iOS device, as far as I'm aware it has to use display: block; and display: none; to hide, which is a tad frustrating. It may be that jQuery or similar provides the most robust solution when animation and tablet / phone support are required.