jQuery animate to transparent

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


        
9条回答
  •  遥遥无期
    2021-01-18 06:30

    Instead of changing background color, remove that attribute!

    The code is as simple as:

    $("li").hover(
        function(){
            $(this).toggleClass('hover', 1000);
        },
        function(){
            $(this).toggleClass('hover', 2000);
        }
    );
    

    Example: http://jsfiddle.net/rdWTE/

    For it to work, you need jQuery and jQuery UI. Does exactly what you wanted (except the colors)!

    Those numbers in jQuery script stand for animation duration in milliseconds.

    EDIT:

    Uhm... Found out that toggleClass can bug from time to time. Better to use addClass on hover, and removeClass on mouse out.

提交回复
热议问题