javascript - CSS transition of a div does not animate -
when click div, want second div expand/collapse. done using js, html, , css. want css transition animate.
right jumping expansion , either scroll (edge) or jump after wait (chrome, opera, firefox).
i've tried set height 1px instead of 0px, doesn't change anything.
function growdiv(id) { var ele = document.getelementbyid(id); if (ele.style.height == '100%') { ele.style.height = '0px'; } else { ele.style.height = '100%'; } }
.main { font-weight: 700; overflow: hidden; cursor: pointer; } .secondary { -webkit-transition: height .5s ease; -moz-transition: height .5s ease; -ms-transition: height .5s ease; -o-transition: height .5s ease; transition: height .5s ease; overflow: hidden; padding-left: 20px; height: 0px; cursor: pointer; }
<div class="main" onclick="growdiv('expandable')"> expand </div> <div class="secondary" id="expandable" onclick="growdiv('expandable')"> number1, <br>number2, <br>number3, <br>number4. </div>
codepen behaves know full site does, measure; here's codepen: http://codepen.io/anon/pen/ezjqjm
are willing use jquery? offers cool animation possibilities, , may accomplish trying do. possible alternative approach.
check out fiddle here:
https://jsfiddle.net/3mo28z1t/11/
<div class="main" id="clicker"> expand </div> <div class="secondary" id="expandable"> number1, <br> number2, <br> number3, <br> number4. </div> <script> $( document ).ready(function() { $(".secondary").hide(); $(document).ready( function(){ $("#clicker").click(function () { $(".secondary").toggle("slow"); }); }); }); </script>
Comments
Post a Comment