jquery - CSS real "slide" toggle not "height" toggle -
i have been looking around while did not find solution trying create.
i have real "slide" toggle, div "moving down in". if take jquery slidetoggle or several css solutions found, modify height of div, don't slide it.
so created own solution animating margin-top property, works nicely, have problem dynamic heights (for example if resize browser-window), not sure how high negative margin-top should make sure slided out, , on other side not delay slide-in because margin-top far out.
i use
margin-top: -100%;
however, if resize window/frame, it's not enough negative margin.
maybe there better solution out there did not find it, created fiddle, share idea , hear suggestions.
update: latest updated fiddle here ... changed few things, feedback!
update - fix typo , tidy up.
i think can use in combination jquery show()
, hide()
code avoid issue.
http://jsfiddle.net/jzj80kzs/7/
$('.switch').click(function(event) { var theswitch = $(this).closest('.block').find('.switch'); var theblock = $(this).closest('.block').find('.details'); if (theblock.hasclass('mt0')) { theswitch.html('+ show'); // change switch dynamically theblock.removeclass('mt0').slideup(function() { $(this).delay(300).hide(); }); } else { theswitch.html('- hide'); theblock.addclass('mt0').slidedown().show(); } });
$('.switch').click(function(event) { var theswitch = $(this).closest('.block').find('.switch'); var theblock = $(this).closest('.block').find('.details'); if (theblock.hasclass('mt0')) { theswitch.html('+ show'); // change switch dynamically theblock.removeclass('mt0').slideup(function() { $(this).delay(300).hide(); }); } else { theswitch.html('- hide'); theblock.addclass('mt0').slidedown().show(); } });
div.block { position: relative; overflow: hidden; border: 1px solid #333; border-bottom: 0px; line-height: 20px; background-color: #fff; } div.block:last-child { border-bottom: 1px solid #333; } div.basics { position: relative; background-color: #fff; z-index: 2; padding: 2px 4px; } div.details { border-top: 1px solid #333; position: relative; background-color: #99f; z-index: 1; height: auto; margin-top: -100%; -webkit-transition: margin-top 600ms cubic-bezier(0.17, 0.04, 0.03, 0.94); -moz-transition: margin-top 600ms cubic-bezier(0.17, 0.04, 0.03, 0.94); -o-transition: margin-top 600ms cubic-bezier(0.17, 0.04, 0.03, 0.94); transition: margin-top 600ms cubic-bezier(0.17, 0.04, 0.03, 0.94); } div.mt0 { margin-top: 0px; } span.switch { float: right; cursor: pointer; font-size: 20px; font-weight: bold; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class="block"> <div class="basics"> lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <span class="switch">+ show</span> </div> <div class="details"> @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. <br />lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. </div> </div> <div class="block"> <div class="basics"> lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <span class="switch">+ show</span> </div> <div class="details"> @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. <br />lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. </div> </div> <div class="block"> <div class="basics"> lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <span class="switch">+ show</span> </div> <div class="details"> @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. <br />lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. </div> </div> <div class="block"> <div class="basics"> lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <span class="switch">+ show</span> </div> <div class="details"> @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. <br />lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. @ vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet. </div> </div>
Comments
Post a Comment