2011-01-21 118 views
0

嘿所有,我有這個任務,我需要將雅虎UI顏色選擇器集成到一個網站。當有人選擇一種顏色時,頁面的背景需要變成那種顏色。如何使用雅虎顏色選擇器來改變背景顏色

我按照這裏的說明http://developer.yahoo.com/yui/colorpicker/#events,但我似乎無法弄清楚如何將backgroundcolor更改爲採摘的顏色。我可以改變背景,當有人選擇一種顏色,但我不知道如何獲得作爲輸入/(見代碼//評論)的顏色,直到現在我有這個:

in head:

<!-- 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給出)看起來升邁克:

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

...所以,嘗試這樣的事情:

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