Add fade-in or fade-out on the addclass / removecl

2019-08-09 03:24发布

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条回答
够拽才男人
2楼-- · 2019-08-09 03:59

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
            });
      });

});
查看更多
登录 后发表回答