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

ⅰ亾dé卋堺 提交于 2019-12-08 04:02:41

问题


I am a beginner, please don't be to rough with me.

I created an addclass and removeclass event :

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

This is the CSS :

#wrapper a.hiding {
   display: none; 
}

And the HTML :

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

So for the moment, it works fine, but I would like to add a fade-in action when addclass, and fade-out when removeclass I tried by the CSS using

 -webkit-transition: all 0.5s ease;

But it's not working.


回答1:


I recommend you try this

edit: I realized just now using fadeIn() is better, try this:

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

});


来源:https://stackoverflow.com/questions/8875542/add-fade-in-or-fade-out-on-the-addclass-removeclass-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!