2011-01-21 16 views
0

こんにちは、私はYahoo UIカラーピッカーをウェブサイトに統合する必要があります。誰かが色を選ぶと、ページの背景がその色になる必要があります。Yahoo!カラーピッカーを使用して背景色を変更する方法

私はここで指示に従いましたhttp://developer.yahoo.com/yui/colorpicker/#eventsしかし、私は選択された色に背景色を変更する方法を考え出すことができないようです。私は誰かが色を選んだときに背景を変更することができますが、これまで入力/(コメントのコードを参照)の色を取得する方法はわかりません:

in head:次に、bodyタグで

<!-- Dependencies --> 
<script src="http://yui.yahooapis.com/2.8.2r1/build/utilities/utilities.js" ></script> 
<script src="http://yui.yahooapis.com/2.8.2r1/build/slider/slider-min.js" ></script> 

    <!-- Color Picker source files for CSS and JavaScript --> 
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.2r1/build/colorpicker/assets/skins/sam/colorpicker.css"> 
<script src="http://yui.yahooapis.com/2.8.2r1/build/colorpicker/colorpicker-min.js" ></script> 

、体内のclass="yui-skin-sam"は:

<div id="container"></div> 
<script type="text/javascript"> 
var picker = new YAHOO.widget.ColorPicker("container", { 
showhsvcontrols: true, 
showhexcontrols: true, 
images: { 
    PICKER_THUMB: "picker_thumb.png", 
    HUE_THUMB: "hue_thumb.png" 
} 
}); 

//a listener for logging RGB color changes; 
//this will only be visible if logger is enabled: 
var onRgbChange = function(o) { 
/*o is an object 
    { newValue: (array of R, G, B values), 
    prevValue: (array of R, G, B values), 
    type: "rgbChange" 
    } 
*/ 
    // with this code i change the background when a color is picked, but not with the input col. 
    // document.body.style.backgroundColor = 'green'; 
YAHOO.log("The new color value is " + o.newValue, "info", "example"); 
} 

//subscribe to the rgbChange event; 
picker.on("rgbChange", onRgbChange); 

    </script> 

答えて

0

RGB値に背景色を設定するための構文は(o.newValueを与えるもの)Lを探しIKE:

document.body.style.backgroundColor = "rgb(" + o.newValue[0] + "," + o.newValue[1] + "," + o.newValue[2] + ");" 

doc.style.backgroundColor="rgb(239,239,239)"; 

...ので、このような何かを試してみてください

関連する問題