Skip to content

Instantly share code, notes, and snippets.

@bizikov
Created May 14, 2014 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bizikov/ea2eb1422f87014d678d to your computer and use it in GitHub Desktop.
Save bizikov/ea2eb1422f87014d678d to your computer and use it in GitHub Desktop.
Перевод RGB в HEX
// Хак для перевода 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