开发者

jQuery UI theme for canvas

开发者 https://www.devze.com 2023-03-17 00:19 出处:网络
I\'m using canvas in web app built with jquery ui. I added t开发者_开发技巧he theme-roller widget and want the canvas elements to be themeable. So the problem I\'m facing is, how do I programatically

I'm using canvas in web app built with jquery ui. I added t开发者_开发技巧he theme-roller widget and want the canvas elements to be themeable. So the problem I'm facing is, how do I programatically access css class properties to use while drawing canvas objects?

this is what I tried:

var color = $("<div></div>").addClass("ui-state-default").css("background-color");  


Got it. The element needed to be added to the DOM.

function getClassProperty(clazz,prop,type){
    type = (type || false) ? type : "div";
    var dummy = $("<"+type+" style='display=none;'></"+type+">").addClass(clazz).appendTo("body");
    var value = dummy.css(prop);
    dummy.remove();
    if(value.indexOf("rgb") != -1){
        var digits = /(.*?)rgba?\((\d+),\s?(\d+),\s?(\d+)[\),]/.exec(value);
        return "#" + (parseInt(digits[4])|(parseInt(digits[3])<<8)|(parseInt(digits[2])<<16)).toString(16);
    }else{
        return value;
    }
}
console.log(getClassproperty("ui-state-default","background-color"));

rgb2hex code taken from: http://haacked.com/archive/2009/12/29/convert-rgb-to-hex.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号