jQuery .css ('backgroundColor' ) 问题

标签 jquery css background get

我的代码有一个小问题。我有一堆具有不同背景颜色的类元素,名为“jq”。我在悬停时为背景颜色设置动画,然后将其恢复为原始颜色:这是 .css('backgroundColor') 应该获得悬停的任何给定 div 和 jq 类的颜色的地方。 相反,我将 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);
                });         
            });

最佳答案

这里有语法错误

$(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

关于jQuery .css ('backgroundColor' ) 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18271271/

相关文章:

javascript - 如何从“通知我”字段中获取电子邮件

html - Chrome 将填充计算为比应有的少一个像素

html - 像内联 block 一样放置 svg-groups

javascript - 悬停时淡化背景颜色

javascript - jQuery + IE8 = 对象不支持此属性或方法。如何解决这个问题?

javascript - 更改 AJAX 响应的格式

windows - 如何从 Windows 上的 Perl CGI 脚本派生后台进程?

jquery - 改变滚动背景颜色

css - 使用 SVG 平铺时只显示一次组

表格为空时的 iPhone UITableView 图像背景