jquery - Transition for a Collapse -
i'm working on custom collapser don't know how can make transition when hiding.
searching online found "display: none;", doesn't support transition.
i've tried height: auto; , height: 0px; doesn't support transition too.
here's code:
html
<a class="clp" href="#clp-1"><div>button</div></a> <div class="clp-body clp-show" id="clp-1">lorem ipsum</div>
css
.clp > div { border: 1px solid black; border-radius: 3px; width: 150px; padding: 5px; } .clp { text-decoration: none; font-family: verdana; color: black; } .clp-body { border: 1px solid black; border-radius: 3px; width: 150px; padding: 5px; margin-top: 5px; transition: 0.5s ease; } .clp-show { opacity: 1; } .clp-show { opacity: 0; display: none; /* example */ }
js (jquery)
$('a.clp').click(function(){ var value = $(this).attr("href"); if ($('div'+(value)).hasclass('clp-show')) { $('div'+(value)).addclass('clp-hide'); $('div'+(value)).removeclass('clp-show'); } else { $('div'+(value)).removeclass('clp-hide'); $('div'+(value)).addclass('clp-show'); }; });
here's link: https://codepen.io/keyon/pen/937706ce73bc3f68cbeff6dd6faf6c87
you can use jquery's slidedown() , slideup() , expand , collapse div this:
$('#clp-1').slidedown(); // expand $('#clp-1').slideup(); // collapse
you'll need remove css line transition: 0.5s ease;
jquery sliding work properly.
Comments
Post a Comment