使用dat.gui的alpha颜色选择器(HTML5)

时间:2013-02-20 21:29:47

标签: javascript html5 dat.gui

有没有办法让一个颜色选择器使用dat.gui(http://code.google.com/p/dat-gui/)修改RGBA颜色的alpha通道?

目前我只能使用颜色选择器更改RGB值 - 即使颜色选择器接受alpha值。

示例(也可用http://jsfiddle.net/mortennobel/PT3g2/1/):

var ColorObject = function() {
   this.color = [ 0, 128, 255, 0.3 ]; // RGB with alpha
    this.showAlert = function(){
        alert("Color is "+this.color);
    } 
};

var colorObject = new ColorObject();
var gui = new dat.GUI();

gui.addColor(colorObject, 'color');
gui.add(colorObject, 'showAlert');  

1 个答案:

答案 0 :(得分:2)

我不确定是否有任何简单的方法来扩展现有的库。我刚刚对库本身进行了更改。你可以在这里试试:http://jsbin.com/anewaz/2

修改后的来源也在我的github上:https://github.com/mariozski/datGUIwithAlpha/blob/master/dat.gui.js

希望它会有所帮助: - )

MZ