How To Add CSS3 Transition With HTML5 details/summary tag reveal?
This should fix it.
details[open] summary ~ * {
animation: sweep .5s ease-in-out;
}
@keyframes sweep {
0% {opacity: 0; margin-left: -10px}
100% {opacity: 1; margin-left: 0px}
}
<details>
<summary>Copyright 1999-2014.</summary>
<p> - by Refsnes Data. All Rights Reserved.</p>
<p>All content and graphics on this web site are the property of the company Refsnes Data.</p>
</details>
Some credit goes to Andrew for pointing this out. I adapted his answer. Here's how this works. By adding the [open]
attribute on the DETAILS
tag, it only fires the animation keyframe when clicked. Then, by adding SUMMARY ~ *
it means "all elements after the SUMMARY
tag" so that the animation applies to those, and not the SUMMARY
element as well.
In addition to Volomike's answer, it would be possible to change margin-left
to transform: translateX()
for performance reasons.
details[open] summary ~ * {
animation: sweep .5s ease-in-out;
}
@keyframes sweep {
0% {opacity: 0; transform: translateX(-10px)}
100% {opacity: 1; transform: translateX(0)}
}
<details>
<summary>Copyright 1999-2014.</summary>
<p> - by Refsnes Data. All Rights Reserved.</p>
<p>All content and graphics on this web site are the property of the company Refsnes Data.</p>
</details>
details
{
transition: height 1s ease;
overflow: hidden;
}
details:not([open])
{
height: 1.25em;
}
details[open]
{
height: 2.50em;
}
<details>
<summary>Example</summary>
Height needs to be set for this to work. Works on Chrome, haven't tested further.
</details>
I recommend you also check out Animate.css here: http://daneden.me/animate. If