2014-01-07 3 views

답변

0

시도가 functions

var hexDigits = new Array 
    ("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); 

//Function to convert hex format to a rgb color 

function rgb2hex(rgb) { 
    rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); 
    return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); 
} 

function hex(x) { 
    return isNaN(x) ? "00" : hexDigits[(x - x % 16)/16] + hexDigits[x % 16]; 
} 

읽기 Convert jQuery RGB output to Hex Color 당신이 hex에서 swatch background color 다음 당신은 colors을받은 후 시도해야 싶어 site source 당신에서 업데이트

이하로 사용하는 감사

alert(rgb2hex($('.swatch').css('background-color'))); 
모든 swatch background-color 사용을 얻을 수 $.each()

+0

고마워요,하지만 어떻게 내 코드에 추가합니까? – user3140235

+0

'alert (rgb2hex ($ ('# yourelement'). css ('background-color'))); ' –

+0

btw와 같이 시도하십시오. 함수 hex (x) {return ('0'+ (+ x || 0) .toString (16)). } –

0
당신은 배경 색상 및 디스플레이 진수를 얻을 수

가 여기에 자바 스크립트 코드 조각입니다 : 얻을 간단하기 때문에,

$('.swatch').on('click', 
    function(){ 
     var context = document.createElement('canvas').getContext('2d'); 
     context.strokeStyle = $(this).css('backgroundColor'); 
     alert(context.strokeStyle); 
}).css('cursor', 'pointer'); 

우리는 캔버스의 사용을 만들거야 실제의 헥스 칼라