//颜色16进制转RGB方法
String.prototype.colorRgb = function(){
var sColor = this.toLowerCase();
//十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
// 如果是16进制颜色
if (sColor && reg.test(sColor)) {
if (sColor.length === 4) {
var sColorNew = "#";
for (var i=1; i<4; i+=1) {
sColorNew += sColor.slice(i, i+1).concat(sColor.slice(i, i+1));
}
sColor = sColorNew;
}
//处理六位的颜色值
var sColorChange = [];
for (var i=1; i<7; i+=2) {
sColorChange.push(parseInt("0x"+sColor.slice(i, i+2)));
}
return "[" + sColorChange.join(",") + ",0.6]";
}
return sColor;
};

js 颜色16进制转RGB方法的更多相关文章

  1. JS实现16进制和RGB转换

    作为前端开发而言,不可避免的会遇到颜色取值,字符串和数字直接的转换,博主为此写了一个小工具,实现色值之间的在线转换. 前置知识点: parseInt, toString parseInt(value ...

  2. 颜色16进制转为RGB格式

    <script> 2 function getRGB(str){ var arr = str.split(""); var myred = arr[1]+arr[2]; ...

  3. JS-011-颜色进制转换(RGB转16进制;16进制转RGB)

    在网页开发的时候,经常需要进行颜色设置,因而经常需要遇到进行颜色进制转换的问题,例如:RGB转16进制:16进制转RGB),前几天在测试的时候,发现网站的颜色进制转换某类16进制颜色(例如:#0000 ...

  4. python2/3中 将base64数据写成图片,并将图片数据转为16进制数据的方法、bytes/string的区别

    1.python2将base64数据写成图片,并将数据转为16进制字符串的方法 import binascii img = u'R0lGODlhagAeAIcAAAAAAAAARAAAiAAAzABE ...

  5. bgcolor RGB 和16进制之间的转换,16进制转RGB,源码

    <p>bgcolor RGB 和16进制之间的转换,16进制转RGB,源码例如:<br /> 输入 201,255,201 转换成 #C9FFC9</p> < ...

  6. C# 颜色有3种表示方式: 6位16进制、RGB、 颜色关键字

    最常用的是6位16进制的代码表示法.如bgcolor=#ff0000;其中#只是表示使用6位16进制的颜色代码声明颜色.代码的头两位即ff表示三原色中的红色,范围当然是16进制的00-ff,中间两位即 ...

  7. js 解密 16进制转10进制,再取ascii码的对应值

    如:\x64 对应 16进制 0x64 转10进制就是 0x64.toString(10) == 100, 查对应的ascii码表得到 ‘d' <div id=code style='displ ...

  8. 网页颜色RGB记法和16进制记法转化方法

    A=>10,B=>11,C=>12,D=>13,E=>14,F=>15 看一个例子: 254,112,85 255/16 等于 15 余 14 那么它对应的应该是F ...

  9. IOS 颜色 16进制 转换

    #define RGB(r,g,b) ([UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]) #define HEXTO ...

随机推荐

  1. [Java]LeetCode116. 填充同一层的兄弟节点 | Populating Next Right Pointers in Each Node

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  2. [Swift]LeetCode202. 快乐数 | Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  3. [Swift]LeetCode437. 路径总和 III | Path Sum III

    You are given a binary tree in which each node contains an integer value. Find the number of paths t ...

  4. [SQL]LeetCode577.员工奖金 | Employee Bonus

    Select all employee's name and bonus whose bonus is < 1000. Table:Employee +-------+--------+---- ...

  5. [Swift]LeetCode598. 范围求和 II | Range Addition II

    Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...

  6. [Swift]LeetCode637. 二叉树的层平均值 | Average of Levels in Binary Tree

    Given a non-empty binary tree, return the average value of the nodes on each level in the form of an ...

  7. [Swift]LeetCode926. 将字符串翻转到单调递增 | Flip String to Monotone Increasing

    A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), ...

  8. [Swift]LeetCode983. 最低票价 | Minimum Cost For Tickets

    In a country popular for train travel, you have planned some train travelling one year in advance.  ...

  9. BBS论坛(十二)

    12.1.图形验证码生成 (1)utils/captcha/init.py import random import string # Image:一个画布 # ImageDraw:一个画笔 # Im ...

  10. metasploit无法连接postgresql

    注:倒数两条可以不做. 问题地址:https://askubuntu.com/questions/50621/cannot-connect-to-postgresql-on-port-5432 设置好 ...