如何覆盖jqcloud中的css?

时间:2016-06-10 12:14:38

标签: javascript jquery jquery-plugins

我试图使用jqcloud在同一个词云中显示三个不同的单词列表,使得来自相同列表的单词应该以相同的颜色显示,并且每个列表的颜色应该不同。

2 个答案:

答案 0 :(得分:0)

说,你有两个数组;

 var word_list1 = new Array(
        {text: "Dolor", weight: 9.4},
        {text: "Sit", weight: 8},
        {text: "Amet", weight: 6.2}};
 var word_list2 = new Array(
        {text: "Consectetur", weight: 5},
        {text: "Adipiscing", weight: 5},
        {text: "Elit", weight: 5},
        {text: "Nam et", weight: 5},
        {text: "Leo", weight: 4}};

您可以添加颜色属性,如;

for (var i = 0; i < word_list1.length; i++) {
    word_list1[i].color = "green";      //i.e. {text: "Leo", weight: 4, color:"green"}};
}       

for (var i = 0; i < word_list2.length; i++) {
    word_list2[i].color = "red";
}       

最后

$("#wordcloud").jQCloud(word_list1.concat(word_list2.concat));

答案 1 :(得分:0)

我终于解决了这个问题。这是步骤:

  1. 首先根据需要创建两个带颜色属性的css类。像:

    .customclass{color:red}
    

    .customclass2{color:green}

  2. 然后在你的单词数组中添加一个额外的元素html并将css类赋给它

    var word_list1 = new Array({text: "Dolor", weight: 9.4, html:{class:'customclass'}},{text: "Sit", weight: 8,html{class:'customclass'}},{text: "Amet", weight:6.2,html{class:'customclass'}}); var word_list2 = new Array({text: "Consectetur", weight: 5, html:{class:'customclass2'}},{text: "Adipiscing", weight: 5,html{class:'customclass2'}},{text: "Elit", weight: 5, html:{class:'customclass2'}},{text: "Nam et", weight: 5, html:{class:'customclass2'}},{text: "Leo", weight: 4,html:{class:'customclass2'}});

  3. 然后像这样呈现云 $("#demo").jQCloud(word_list1.concat(word_list2.concat));