javascript - Using jquery slidetoggle on visibility hidden elements? -
i trying figure out way use slidetoggle on elements set visibility: hidden, rather display: none.
the reason because text slidetoggling causing div within stretch out. there method can use keep element want slidetoggle slide within place without div expanding?
html:
<section id="image-gallery"> <div class="container"> <div id="imageboxing" class="disciplines"> <img src="images/martial-arts-banner/boxing.png"> <h3>boxing</h3> </div> <div id="imagekb" class="disciplines"> <img src="images/martial-arts-banner/kickboxing.png"> <h3>kickboxing</h3> </div> <div id="muaythai" class="disciplines"> <img src="images/martial-arts-banner/muaythai.png"> <h3>muaythai</h3> </div> <div id="wrestling" class="disciplines"> <img src="images/martial-arts-banner/wrestling.png"> <h3>wrestling</h3> </div> <div class="clear"></div> </div>
jquery:
$(document).ready(function() { $(".disciplines img").hover(function(){ $(this).next().slidetoggle(); }) });
you wrap h3
element inside div
:
<div> <h3>boxing</h3> </div>
and give fixed height:
.disciplines div { height: 50px; } h3 { margin: 0; }
don't forget modify selector to:
$('h3', this.parent).slidetoggle();
or:
$(this).next().find('h3').slidetoggle();
or similar.
$(document).ready(function() { $(".disciplines img").hover(function() { $(this).next().find('h3').slidetoggle(); }) });
.disciplines div { height: 50px; } h3 { margin: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <section id="image-gallery"> <div class="container"> <div id="imageboxing" class="disciplines"> <img src="https://www.wikipedia.org/portal/wikipedia.org/assets/img/wikipedia-logo-v2.png"> <div> <h3>boxing</h3> </div> </div> <div id="imagekb" class="disciplines"> <img src="https://www.wikipedia.org/portal/wikipedia.org/assets/img/wikipedia-logo-v2.png"> <div class="fh"> <h3>kickboxing</h3> </div> </div> <div class="clear"></div> </div>
Comments
Post a Comment