1

コードにちょっとした問題があります。「jq」という名前の、背景色が異なるクラス要素がたくさんあります。ホバー時に背景色をアニメーション化し、元の色に戻します。これは、.css('backgroundColor') がホバーされ、jq クラスを使用して指定された div の色を取得する場所です。代わりに、div の背景を白に戻します。これが私のコードです:

$(document).ready(function(){   
            $(".jq").hover( 
            var bgcol = $(this).css('backgroundColor');
                function(){ 
                  $(this).animate({     
                     backgroundColor: "#EAEAEA",
                     color:"#333"
                  },trans);
                },
                function() {      
                  $(this).animate({
                    backgroundColor:'bgcol',
                     color:"#888"
                  },trans);
                });         
            });
4

1 に答える 1

1

ここに構文エラーがあります

$(document).ready(function(){   
    $(".jq").hover( 
        function(){ 
            var bgcol = $(this).css('backgroundColor');
            $(this).animate({     
                backgroundColor: "#EAEAEA",
                color:"#333"
            }, trans).data('hoverbackground', bgcol);
        },
        function() {      
            $(this).animate({
                backgroundColor: $(this).data('hoverbackground'),
                //backgroundColor: "#EFEFEF",
                color:"#888"
            }, trans).removeData('hoverbackground');
        });         
});

デモ:フィドル

于 2013-08-16T10:35:45.170 に答える