jQuery animate backgroundColor

前端 未结 17 2124
醉梦人生
醉梦人生 2020-11-21 07:11

I am trying to animate a change in backgroundColor using jQuery on mouseover.

I have checked some example and I seem to have it right, it works with other properties

17条回答
  •  情深已故
    2020-11-21 08:00

    You can use 2 divs:

    You could put a clone on top of it and fade the original out while fading the clone in.

    When the fades are done, restore the original with the new bg.

    $(function(){
        var $mytd = $('#mytd'), $elie = $mytd.clone(), os = $mytd.offset();
    
          // Create clone w other bg and position it on original
        $elie.toggleClass("class1, class2").appendTo("body")
             .offset({top: os.top, left: os.left}).hide();
    
        $mytd.mouseover(function() {            
              // Fade original
            $mytd.fadeOut(3000, function() {
                $mytd.toggleClass("class1, class2").show();
                $elie.toggleClass("class1, class2").hide();            
            });
              // Show clone at same time
            $elie.fadeIn(3000);
        });
    });​
    

    jsFiddle example


    .toggleClass()
    .offset()
    .fadeIn()
    .fadeOut()

提交回复
热议问题