jquery animate .css

前端 未结 5 1458
醉梦人生
醉梦人生 2020-12-05 13:55

I have a script:

$(\'#hfont1\').hover(
    function() {
        $(this).css({\"color\":\"#efbe5c\",\"font-size\":\"52pt\"}); //mouseover
    }, 
    function         


        
5条回答
  •  暖寄归人
    2020-12-05 14:29

    Just use .animate() instead of .css() (with a duration if you want), like this:

    $('#hfont1').hover(function() {
        $(this).animate({"color":"#efbe5c","font-size":"52pt"}, 1000);
    }, function() {
        $(this).animate({"color":"#e8a010","font-size":"48pt"}, 1000);
    });
    

    You can test it here. Note though, you need either the jQuery color plugin, or jQuery UI included to animate the color. In the above, the duration is 1000ms, you can change it, or just leave it off for the default 400ms duration.

提交回复
热议问题