From f3589626755a83c541d4d2eccf7b8038fd3f1e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sat, 22 Apr 2023 16:13:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20colorpicker=20=E5=9C=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=88=9D=E5=A7=8B=E5=80=BC=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E4=B8=AD=E8=BE=93=E5=85=A5=E6=A1=86=E6=9C=AA?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/colorpicker.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/modules/colorpicker.js b/src/modules/colorpicker.js index 03752acd..7d1f90c5 100644 --- a/src/modules/colorpicker.js +++ b/src/modules/colorpicker.js @@ -359,16 +359,13 @@ layui.define(['jquery', 'lay'], function(exports){ //同步滑块的位置及颜色选择器的选择 that.select(hsb.h, hsb.s, hsb.b); - //如果格式要求为rgb + // 若格式要求为rgb if(type === 'torgb'){ elemPickerInput.find('input').val(bgcolor); - } - - //如果格式要求为rgba - if(type === 'rgba'){ + } else if(type === 'rgba'){ // 若格式要求为 rgba var rgb = RGBSTo(bgcolor); - //如果开启透明度而没有设置,则给默认值 + // 若开启透明度而没有设置,则给默认值 if((bgcolor.match(/[0-9]{1,3}/g) || []).length === 3){ elemPickerInput.find('input').val('rgba('+ rgb.r +', '+ rgb.g +', '+ rgb.b +', 1)'); that.elemPicker.find('.'+ PICKER_ALPHA_SLIDER).css("left", 280); @@ -378,12 +375,13 @@ layui.define(['jquery', 'lay'], function(exports){ that.elemPicker.find('.'+ PICKER_ALPHA_SLIDER).css("left", left); } - //设置span背景色 + // 设置 span 背景色 that.elemPicker.find('.'+ PICKER_ALPHA_BG)[0].style.background = 'linear-gradient(to right, rgba('+ rgb.r +', '+ rgb.g +', '+ rgb.b +', 0), rgb('+ rgb.r +', '+ rgb.g +', '+ rgb.b +'))'; + } else { + elemPickerInput.find('input').val('#'+ HSBToHEX(hsb)); } - - }else{ - //如果没有背景颜色则默认到最初始的状态 + } else { + // 若没有背景颜色则默认到最初始的状态 that.select(0,100,100); elemPickerInput.find('input').val(""); that.elemPicker.find('.'+ PICKER_ALPHA_BG)[0].style.background = '';