Created
May 14, 2014 05:31
-
-
Save bizikov/ea2eb1422f87014d678d to your computer and use it in GitHub Desktop.
Перевод RGB в HEX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Хак для перевода RGB в HEX | |
$.cssHooks.backgroundColor = { | |
get: function (elem) { | |
if (elem.currentStyle) | |
var bg = elem.currentStyle["backgroundColor"]; | |
else if (window.getComputedStyle) | |
var bg = document.defaultView.getComputedStyle(elem, | |
null).getPropertyValue("background-color"); | |
if (bg.search("rgb") == -1) | |
return bg; | |
else { | |
bg = bg.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); | |
function hex(x) { | |
return ("0" + parseInt(x).toString(16)).slice(-2); | |
} | |
return "#" + hex(bg[1]) + hex(bg[2]) + hex(bg[3]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment