Smooth transition when updating the list, all hidden items don't display as blank in layout. It animates at the parent level (ul/ol) rather than the individual level (li), to overcome several challenges:
- Use
height:0
transition will hide the item smoothly, but it presents several issues: a) to show the item, you must provide exact pixel for height, and each item height is different so it's not possible with css alone. b) another way to get around this is when before showing the item, remove the previous hide class, it will reset the height to original, however it jerks the layout, because the height is restored before the transition. - Use
display:none
in animation doesn't work, so putting in the last keyframe doesn't do anything. - Use scale, transition, position:absolute to remove from the layout, it has the same issue as 1b. Also with position:absolute, when animating before opacity:0, the contents overlap each other, because position:absolute removes itself the flow of elements on the page.
So rather to hide or show individual item, I hide the whole list. While it's hidden,javascript hides and shows individual items, animates the whole list. With keyframes animation, I can control the time, and allow javascript to finish its work before showing the list. So in keyframes, from 0-5%, opacity is 0, this provides enough time for javascript, if not I increase it to 10%.