Using fade in/fade out with jquery

后端 未结 4 1737
余生分开走
余生分开走 2021-01-27 05:48

I am working over on of my student projects and I am new jquery, for the project I have to use jquery to enhance few function and I have learned much to carry out basic tasks, b

4条回答
  •  日久生厌
    2021-01-27 06:40

    You want to access the callback function of the fadeIn and fadeOut functions, this will allow you to make changes to the src image and what not. it would look something like this ->

    $(document).ready(function () {
      $(".thumb").hover(function () {
        var dummyImg = $(this).attr("alt");
        $(this).fadeOut('slow', function(){
          //this is now the callback.
          $(this).attr("alt", $(this).attr("src"));
          $(this).attr("src", dummyImg);
          $(this).fadeIn('slow');
        });
      }, function () {
        var dummyImg = $(this).attr("src");
        $(this).fadeOut('slow', function(){
          //this is now the callback.
          $(this).attr("src", $(this).attr("alt"));
          $(this).attr("alt", dummyImg);
          $(this).fadeIn('slow');   
        });
      });
    });
    

提交回复
热议问题