簡體   English   中英

在fadeIn前添加fadeOut

[英]Add fadeOut in front of fadeIn

我使用這個腳本來過濾基於類的元素。 目前它停止以前的功能並淡入新班級。

基本上我需要在開始淡入選擇器之前淡出所有內容。 目前它是從 100% 不透明度到開始淡入選擇器的銳減,我想平滑淡出當前(或特定類),然后淡入這個。

我的代碼:

 $('div.tags').delegate('input[type=radio]', 'change', update); update(); function update() { var $lis = $('.results > div'), $checked = $('input:checked'); if ($checked.length) { var selector = $checked.map(function () { return '.' + $(this).attr('rel'); }).get().join(''); $lis.hide().filter(selector).stop().fadeIn(1000, 'easeInCirc'); } else { $lis.stop().fadeIn(1000, 'easeInCirc'); } }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="tags"> <label class="odseba"> <input class="fadeout" type="radio" checked="checked" rel="all" name="gg" /><span>VŠETKO</span></label> <label class="odseba"> <input type="radio" rel="web" name="gg" /><span>WEB</span></label> <label class="odseba"> <input type="radio" rel="eshop" name="gg" /><span>ESHOP</span></label> <label class="odseba"> <input type="radio" rel="seo" name="gg" /><span>SEO</span></label> <label class="odseba"> <input type="radio" rel="grafika" name="gg" /><span>GRAFIKA</span></label> <label class="odseba"> <input type="radio" rel="logo" name="gg" /><span>LOGO</span></label> <label class="odseba"> <input type="radio" rel="reklama" name="gg" /><span>REKLAMA</span></label> <label class="odseba"> <input type="radio" rel="kampan" name="gg" /><span>KAMPAŇ</span></label> <label class="odseba"> <input type="radio" rel="branding" name="gg" /><span>BRANDING</span></label> <label class="odseba"> <input type="radio" rel="print" name="gg" /><span>PRINT</span></label> </div> and these are idems being filtered: <div class="span4 thumb-pad0 all web eshop print seo"> <div class="thumbnail"> <figure><a href="img/img5.jpg"><img src="img/page3_pic5.jpg" alt=""></a></figure> <div class="caption"> <h2 style="font:28px/28px 'Century Gothic', 'Century Gothic', Arial, Helvetica, Century Gothic; color:#FFF; text-transform:uppercase; margin:0;">Name</h2> <p>lorem ipsum</p> </div> </div> </div>

將fadeIn() 作為回調傳遞給fadeOut():

} else {
    $("elements-to-fade-out").fadeOut(1000, "easeInCirc", function() {
        $lis.stop().fadeIn(1000, 'easeInCirc');
    });
}

你也可以這樣做:

} else {
    $("elements-to-fade-out").fadeOut(1000, "easeInCirc");

    // Fade in after 1000
    //
    setTimeout(function() {
        $lis.stop().fadeIn(1000, "easeInCirc");
    }, 1000);
}

有關回調的信息,請參見此處:

http://www.w3schools.com/jquery/eff_fadein.asp

淡出所有元素,然后使用回調函數淡入特定元素:

$lis.fadeOut(1000, 'easeInCirc', function(){
   $(this).filter(selector).fadeIn(1000, 'easeInCirc');
});

http://plnkr.co/edit/0wkJGOgK3hxIfLX3RqKF?p=info

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM