javascript - jQuery how to make slideToggle applies one each item -
how can make toggle fadein fadeout applies on each items
block? when click anyone, applies of them. please ? thanks
<div class="items"> <div class="warp"> <span class="change">tester</span> <span class="click">expand</span> </div> <div class="invisible"> <div class="red"> red </div> <div class="black"> black </div> </div> </div> <div class="items"> <div class="warp"> <span class="change">tester</span> <span class="click">expand</span> </div> <div class="invisible"> <div class="red"> red </div> <div class="black"> black </div> </div> </div>
jquery
$('.invisible').hide(); $('.warp').addclass('bg'); $(".warp").click(function () { $(".invisible").slidetoggle("slow", function () { if ($(this).is(':visible')) { $('.warp').removeclass('bg'); }else{ $('span.click').css('visibility', 'visible'); $('.warp').addclass('bg'); } }); $('span.click').css('visibility', 'hidden'); });
how can make toggle fadein fadeout applies on each itemsblock? when click anyone, applies of them.
this because use $(".invisible")
selects elements class invisible
. have find element related toggle element(your .warp
element), in case this: $warp.next(".invisible")
.
see updated fiddle.
updated jquery code:
$(".warp").click(function () { var $warp = $(this); $warp.next(".invisible").slidetoggle("slow", function () { if ($(this).is(':visible')) { $warp.removeclass('bg'); }else{ $warp.find('span.click').css('visibility', 'visible'); $warp.addclass('bg'); } }); $warp.find('span.click').css('visibility', 'hidden'); });
Comments
Post a Comment