jQuery animate to transparent

前端 未结 9 2001
迷失自我
迷失自我 2021-01-18 06:05
$(\".block li\").hover(
    function(){
        $(this).animate({backgroundColor: \"#000\"});
    },
    function(){
        $(this).animate({backgroundColor: \"#fff         


        
9条回答
  •  猫巷女王i
    2021-01-18 06:28

    Edit: I have tested this and it works.

    Create two classes. One with background: #000 and one with background: transparent;

    Animate the toggleClass or removeClass for the #000 background class.

    example:

    jQuery('.block li').hover(function() {
      $(this).toggleClass('blackClass', 'fast' );
    }
    

    CSS:

    .blackClass { background: #000; }
    

提交回复
热议问题