【问题标题】:set background color in javascript在javascript中设置背景颜色
【发布时间】:2012-10-16 21:39:46
【问题描述】:

我一直在尝试解决这个问题,但似乎无论我多么努力,我似乎​​都无法正确解决。我有一个带有星形坐标的地图视图。星星在悬停时会改变颜色,并在点击时打开一个链接。你如何设置背景颜色? (不是悬停颜色,我明白了。只是主要的。代码:

for (var country in onestar) {
    var obj = r.path(onestar[country].path);

    obj.attr(attributes);

    arr[obj.id] = country;



    obj
    .hover(function(){


    this.animate({
            fill: '#41464e'
        }, 300);
    }, function(){
        this.animate({
            fill: attributes.fill
        }, 300);
    })
    .click(function(){


    window.open('http://www.yahoo.com/')


    });

    $('.point').find('.close').live('click', function(){
        var t = $(this),
            parent = t.parent('.point');

        parent.fadeOut(function(){
            parent.remove();
        });
        return false;
    });


}

我尝试的每件事都会出错。 :(

【问题讨论】:

  • 能否提供完整代码,最好是jsfiddle.net
  • 您所做的似乎不是标准的 DOM 事情。这是 Raphael 应用程序吗?

标签: javascript jquery colors background


【解决方案1】:

如果您使用的是jquery ui 1.9+ ,请尝试使用backgroundColor 而不是fill

【讨论】:

  • +1 表示 jQuery UI 是标准 jQuery API 的附加组件。
  • 我提到它是因为看起来他正在使用某个版本的 jQueryUI。 v1.9+ 现在允许您在背景颜色之间制作动画。
【解决方案2】:
$('your selector').css('background-color','your color'); 

应该这样做。

http://api.jquery.com/css/

【讨论】:

    猜你喜欢
    • 2011-08-31
    • 1970-01-01
    • 2011-06-06
    • 2011-03-25
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多