【问题标题】:jQuery .css('backgroundColor') issuejQuery .css('backgroundColor') 问题
【发布时间】:2013-08-16 18:41:06
【问题描述】:

我的代码有一点问题。我有一堆具有不同背景颜色的类元素,名为“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);
                });         
            });

【问题讨论】:

  • 你试过了吗:背景颜色你的文字有点乱

标签: jquery css background get


【解决方案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');
        });         
});

演示:Fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 2012-01-04
    • 1970-01-01
    相关资源
    最近更新 更多