/ * ************************************************************ color processing ********************* ************* * / // hex color rgb color transfer function HexToRgb (STR) { var R & lt = / ^ \ # [0-9A-F.]. 6} {$ /? ; / / the Test method to check whether there is a pattern in a string, then return if there is true, otherwise false IF (R.TEST (str)!) return window.alert ( "input error of hex" ); // the replace replace Find to string STR = str.replace ( "#", "" ); // match query array obtained var HXS = str.match (/../ G); // Alert ( 'BF:' + HXS) for ( var I = 0; I <. 3; I ++) HXS [I] = the parseInt ([I] HXS, 16); //alert(parseInt(80, 16)) //console.log(hxs); return hxs; } // GRB color Color Hex turn function RgbToHex (A, B, C) { var R & lt = / ^ \ $ D {l, 3} / ; IF (R.TEST (A) || R.TEST (B)!! R.TEST || (C))! return window.alert ( "rgb color value of the input error" ); var hexs = [a.toString (16), b.toString (16), c.toString (16 )] ; for ( var I = 0; I <. 3; I ++) IF (hexs [I] == .length. 1) hexs [I] = "0" + hexs [I]; return "#" + hexs.join ( " " ); } // get color values darken hex color value, level of deeper level, the margin between 0-1 function getDarkColor (color, level) { var R & lt = / ^ \ #? [0-9A-F.]. 6 { $} / ; IF (R.TEST (color)!) return window.alert ( "hex color value of the input error" ); var RGBC = the this .HexToRgb (color); // Floor rounded down for ( var I 0 =; I <. 3; I ++) RGBC [I] = Math.floor (RGBC [I] * (. 1 - Level)); return the this .RgbToHex (RGBC [0], RGBC [. 1], RGBC [2 ]) ; } // get color values Dodge hex color values of color, level of deeper level, the limit between 0-1 function getLightColor (color, level) { var R & lt = / ^ \ #? [0-9A-F.] { } $. 6 / ; IF (R.TEST (color)!) return window.alert ( "hex color value of the input error" ); var RGBC = the this .HexToRgb (color); for ( var I = 0; I <. 3 ; I ++) RGBC [I] Math.floor = ((255 - RGBC [I]) + * Level RGBC [I]); return the this .RgbToHex (RGBC [0], RGBC [. 1], RGBC [2 ]); } / * *************************** color processing end ****************** ******************* * /
----------------
Disclaimer: This article is CSDN blogger "dead of night, knocking codes" of the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and link this statement.
Original link: https: //blog.csdn.net/zhh0310235/article/details/99985866