I have a list with icons, when the icons are clicked the text is revealed. This works - just using opacity
and toggling a class. But the problem is if the text wraps over one line, you get space between each of the icons.
I've tried toggling between display: none / block
which does collapse the space ...but then the content 'jumps' into view.
Is there a way once the content is displayed with .visible
as well as fading in, the height could also animate smoothly pushing the rest of the content down?
$('.list-numbers--reveal li').click(function() {
$(this).toggleClass('visible');
});
.list-numbers {
counter-reset: li;
line-height: 1.25;
list-style: none;
}
.list-numbers li {
display: flex;
min-height: 24px;
margin-bottom: 12px;
position: relative;
text-decoration: none;
text-shadow: none;
}
.list-numbers li:before {
background: black;
border-radius: 100%;
color: white;
content: counter(li);
counter-increment: li;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
font-size: 14px;
height: 24px;
line-height: 14px;
margin-right: 8px;
position: relative;
top: -2px;
width: 24px;
}
.list-numbers--reveal li {
cursor: pointer;
}
.list-numbers--reveal li span {
opacity: 0;
transition: opacity .12s;
}
.list-numbers--reveal li.visible span {
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<ol class="list-numbers list-numbers--reveal">
<li><span>Lorem</span></li>
<li><span>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</span></li>
<li><span>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</span></li>
<li><span>Duis aute irure</span></li>
</ol>