Tiffany B. Brown

Toggle ‘blind’ effect with CSS3 transitions

Transitioning between an ‘open’ state and a ‘closed’ state when the height of your content is variable (making a transition of the height property inadequate).

What makes the magic? Using height: auto, and transitioning the min-height and max-height properties instead.

View the demo, or study / steal the code.

This example makes use of CSS3 transitions, and DOMTokenList / classList. There’s also a fallback that uses className and some regular expression-ism in browsers that don’t yet support classList.

5 Responses to “Toggle ‘blind’ effect with CSS3 transitions”

  1. Tom Cavill says:

    This is great; concise and clean. Thanks.

    Do you know what adjustments are necessary to have this multiple times on one page?

    Thanks in advance, 

  2. tiffanybbrown says:

    You should only have to change the item or items to which you attach the event handler. So if you want it to apply to all items with a .trigger class, you could.

  3. Tom Cavill says:

    I thought as much but couldn’t get it to work.

    Here’s my fiddle:

    My JS ability is very low, so no doubt it’s something simple.

  4. tiffanybbrown says:

    It’s not super simple. It does take a little more know-how. Step 1 is to use querySelectorAll() or getElementsByClassName() instead of querySelector() to get everything with a .foo class. querySelector() just returns the first such item. More here:

    Then you can iterate over the entire list. Or use event delegation. I forked your fiddle, and included examples of how to do both.

  5. Tom Cavill says:

    I see. Thanks for taking the time out; I’ve had a play in jsfiddle and think I understand it now. Much appreciated.