jQueryを使って背景の色を変更しようとしています。色の名前とその値の配列を作成しました。
私が行った場合
console.log(colorValue);
対応する色を見つけるために使用したいクラス名を取得します。
console.log(colorArr.colorValue);
私は undefined を取得しますが、そうすると
console.log(colorArr.red);
対応する色を取得します:
function colorChange(){
$('div.colorpicker ul li a').on('click', function() {
var colorArr = {'greenyellow': '#d2db46', 'lightgreen': '#8dc13f', 'darkgreen': '#56a174', 'blauw' : '#3199d1', 'darkblue':'#326b9b', 'darkpurple':'#584586' , 'purple':'#985494', 'red':'#ca4538', 'orange' : '#e27a37', 'darkyellow': '#f8c040', 'lightyellow': '#e4de42'};
var changeBackground = $('div.header_blue, div.reactie, section#adres, section#referenties_single div.pager');
var changeColor = $('section#tevredenklanten h1, section#referenties_single h2.klant, section#referenties_single .wat_gedaan h2');
var colorValue = $(this).attr('class');
console.log(colorValue);
//console.log(colorArr);
console.log(colorArr.colorValue);
//console.log(colorArr.red);
changeBackground.animate({backgroundColor:colorArr.colorValue}, 600);
});
}
私が何をしなければならないか知っている人はいますか?