javascript支持自定义色块的颜色选择器插件

所属分类: 网页特效-实用工具    2024-12-11 11:01:45

javascript支持自定义色块的颜色选择器插件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript支持自定义色块的颜色选择器插件(共3个文件)

    • index.html

使用方法

 var ColorPicker;

 (function() {

   function insertBefore(element, before) {
     parent = before.parentNode;
     parent.insertBefore(element, before);
   }

   function extend(defaults, options) {
     var extended = {};
     var prop;
     for (prop in defaults) {
       if (Object.prototype.hasOwnProperty.call(defaults, prop)) {
         extended[prop] = defaults[prop];
       }
     }
     for (prop in options) {
       if (Object.prototype.hasOwnProperty.call(options, prop)) {
         extended[prop] = options[prop];
       }
     }
     return extended;
   };

   function hasClass(element, classname) {
     var className = " " + classname + " ";
     if ((" " + element.className + " ").replace(/[\n\t]/g, " ").indexOf(" " + classname + " ") > -1) {
       return true;
     }
     return false;
   }

   function removeClass(node, className) {
     node.className = node.className.replace(
       new RegExp('(^|\\s+)' + className + '(\\s+|$)', 'g'),
       '$1'
     ).replace(/ +(?= )/g, '').trim();
   }

   function addClass(element, className) {
     if (!hasClass(element, className)) {
       element.className += ' ' + className;
       element.className = element.className.replace(/ +(?= )/g, '').trim()
     }
   }

   ColorPicker = function(element, options) {

     this.options = extend({
       color: '#e7e7e7',
       palettes: ['#646fff', '#fffa1d', '#ffa21f', '#ff391d'],
       onUpdate: function() {}
     }, options);

     this.options.palettes.unshift(this.options.color);

     this.hex = this.options.color;
     this.rgb = this.HEXtoRGB(this.hex);
     this.hsv = this.RGBtoHSV(this.rgb[0], this.rgb[1], this.rgb[2]);
     this.dom = {};
     this.dom.container = document.createElement('div');
     this.dom.container.className = 'color-picker-container';

     element.appendChild(this.dom.container);

     this.initPicker();

     this.initPalettes();
   }

   ColorPicker.prototype.initPicker = function() {

     this.dom.picker = {};
     this.dom.picker.container = document.createElement('div');
     this.dom.picker.container.className = 'picker-container';

     this.dom.container.appendChild(this.dom.picker.container);

     this.dom.picker.canvas = {};

     this.dom.picker.canvas.container = document.createElement('div');
     this.dom.picker.canvas.container.className = 'canvas-container';
     this.dom.picker.container.appendChild(this.dom.picker.canvas.container);

     this.dom.picker.canvas.canvas = document.createElement('canvas');
     this.dom.picker.canvas.canvas.className = 'canvas';

     this.dom.picker.canvas.pointer = document.createElement('div');
     this.dom.picker.canvas.pointer.className = 'pointer';

     var ctx = this.dom.picker.canvas.canvas.getContext('2d'),
       image = new Image,
       $this = this,
       dragging = false;

     this.dom.picker.canvas.canvas.setAttribute('width', 200);
     this.dom.picker.canvas.canvas.setAttribute('height', 200);
     this.dom.picker.canvas.container.appendChild(this.dom.picker.canvas.canvas);
     this.dom.picker.canvas.container.appendChild(this.dom.picker.canvas.pointer);

     // image.src = 'images/wheel copy.png';
     image.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtoAAALaCAYAAAAP7vQzAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAABs6BJREFUeNrsnXecZEW5/p/q2QnkjKggQQVUchQQRIJESYIgiChiVoKKV73+rl7vVa8555xQEFCULIggQXKSIElABSTD5t2Zqd8fm2a6T1W9qc45PVv1+Siz06erT3fP7nzP08/7PA5llVVWWWWR16F7AkPDAMYnf/89h2Nwh+2wAuZgBXisAGD5hf9bDh4rA1gVwEoAVoLH8gBWANyCYzyWARb/bwQewwAGAQzCYxBAB8AAAAcPAPALz2AcHmMA5gGYD2AePOYCmANgNoBZ8JgFYCaA6fB+OoBnF/7vKXg8CWAGgBnwC/8LTAcwHcOY8ae/AN/7fdcL0AFmzwZ+8+fys9C29fa3vx3f/va3ywtRVlktWq68BGWVVVZZwEorANtvCWB04T+ODnjboVh+5ZWxIsawIoAVp3Ww6k5b4jkD07AaxrEa4FZZCNCrYRwrdMHyCIARAMMAhhYC8pIV+zPnWM59e28bAzB34f/mwC8G9AX/9XgCDk8uhPInAP8EHB6fPw//vvJWPDvmF0J7B888/iRGf3DuhL0HgCtvAWbMLj9bBbTL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oc7xfFAg5g5GhCwwuADNU8LbVrcdAmHU/Qbwfew+LNBEqFIf2zWEDyQrVsfvNxhDOQgffuP5ef/mXzwMu/RvwjyfL74SyyiqgXVZZBmujDYGTT8Jz3nAkjhlewR0HjxdPUrCrIErizZb8WR0JSATp7u9ZNEZ2AzprcJICyy7j4KOBcm3WPulrsIykoNQArmN7JtVvSfQfJ1c7d2lNTiuJkQIOPxeDOBvAN2fN8n/8yeXAFy4A7n2s/I4oq6wC2mWVJQHsFwMnvx9rHX0U3jy0vHsr5mJ9jC+EP4liLfZmM33WIoCv2iP1/BJQW0e8X2pP8v2pcA+dSl7X4GMSWil/9sJ9vE2TZCvi/YygmwvMYkhXQLX31PuNooNzMIyvzZ7uL/7R5cAXzgfuKxXvZZVVQLussihrZIEH+znf/jqOHVrOvQ3zsB7GwCiXqQO+lX9mgbSiVdKi2Mb89hjsI9PgoyaX2wDUpTBN2reB7OzoHgEFneXBDgG5lU2EAd0mxxNytvkwvgC4R/C1WTP8xW/7MXDaNcD8klJSVlkFtMsqqxKwh4EjjsAqJx6P4zbfyr1rMWBzhhpFUGwwKBk8huHVFoE0NSJQCta5s7VjFwghkMuYONK9v2gvib2D8/y5hTaKvGyy+u355xt8HjXbRHoAXtssGV

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

js在线自定义更改元素CSS工具代码

核心功能使用进度滑块和颜色选择器等在线动态更改CSS特效。可自定义设置间距、背景颜色和模糊等级等。
  实用工具
 8207  0

jquery基于clipboard代码全选复制插件

Code Box Copy是一个常用的Prism语法高亮器插件,可自定义的复制按钮将代码框中的内容复制到剪贴板。
  实用工具
 5195  0

jquery带画笔橡皮擦功能的在线涂鸦插件

一款在线涂鸦工具插件,可直接将网页变成画布,可以用鼠标在页面上涂抹、涂鸦和绘图。使用它可以突出显示网页的重要内容,写笔记或评论,并与朋友分享你的笔记。
  实用工具
 4228  0

javascript短篇小说在线生成工具

使用了预定义的短文模板并替换自定义字符等随机创建文章内容,可助于生成具有自定义细节的内容丰富的短篇文章小说。
  实用工具
 2217  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论