簡體   English   中英

在 addclass / removeclass 事件上添加淡入或淡出

[英]Add fade-in or fade-out on the addclass / removeclass event

我創建了一個addclassremoveclass事件:

$(".myclass").click(function(){
   $(".hiding").removeClass("hiding");
   $(this).addClass("hiding");
});

使用以下 CSS:

#wrapper a.hiding {
   display: none; 
}

和 HTML :

<div id="wrapper">
    <a class="myclass" href="#2">
        <img src="example.png">
    </a>
</div>

addclass被觸發時,我似乎找不到添加fade-in動作的方法。 我還想在觸發removeClass時添加fade-out

我嘗試了以下 CSS 沒有成功:

 transition: all 0.5s ease;

有沒有更好的方法通過Javascript?

我建議你試試這個

編輯:我剛剛意識到使用fadeIn() 更好,試試這個:

$(".myclass").click(function(){
   $(".hiding").fadeOut('slow', function() {
       $(".hiding").removeClass("oldStuffHere");
       $(this).addClass("newStuffHere");
       $(this).fadeIn('slow', function() {
           // Animation complete
            });
      });

});

暫無
暫無

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

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