jsp页面引入调色板、颜色表

2024-05-26 02:18

本文主要是介绍jsp页面引入调色板、颜色表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

jsp页面:
<form>
<input id="fontColor"/>
<div id="colorpanel" style="position:absolute;display:none; width:253px;height:177px;"></div> 
</form>
javascript脚本:
$(document).ready(function() {
   initPanel(); //初始化调色板
   $("#fontColor").bind("click", OnDocumentClick); //fontColor:调用调色板的控件ID
});


js内容:

var ColorHex = new Array('00', '33', '66', '99', 'CC', 'FF');
var SpColorHex = new Array('FF0000', '00FF00', '0000FF', 'FFFF00', '00FFFF','FF00FF');

var current = null 
 
//初始化调色板 
function initPanel() { 
   var colorTable = '' 
   for (i = 0; i < 2; i++) { 
       for (j = 0; j < 6; j++) { 
           colorTable = colorTable + '<tr style="height:12px;">' 
           colorTable = colorTable + '<td style="width=11px;height:12px;background-color:#000000">' 
           if (i == 0) { 
               colorTable = colorTable + '<td style="width=11px;height:12px;background-color:#' + ColorHex[j] + ColorHex[j] + ColorHex[j] + '">' 
           } 
           else { 
               colorTable = colorTable + '<td style="width=11px;height:12px;background-color:#' + SpColorHex[j] + '">' 
           } 
           colorTable = colorTable + '<td style="width=11px;height:12px;background-color:#000000">' 
           for (k = 0; k < 3; k++) { 
               for (l = 0; l < 6; l++) { 
                   colorTable = colorTable + '<td style="width=11px;height:12px;background-color:#' + ColorHex[k + i * 3] + ColorHex[l] + ColorHex[j] + '">' 
               } 
           } 
       } 
   } 
   colorTable = '<table width=253 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse;" bordercolor="000000">' 
          + '<tr height="30px"><td colspan=21 bgcolor=#cccccc>' + '<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">'
          + '<tr><td width="3"><td><input type="text" id="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>'
          + '<td width="3"><td><input type="text" id="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"></td><td align="right" width="100%"><span id="spnClose" style="cursor:hand;">Ⅹ</span>&nbsp;</td></tr></table></td></table>' 
      + '<table  width=253  id="tblColor" border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" style="cursor:hand;">' 
                 + colorTable + '</table>'; 
          $("#colorpanel").html(colorTable); 
          $("#tblColor").bind("mouseover", doOver); 
          $("#tblColor").bind("mouseout", doOut); 
          $("#tblColor").bind("click", doclick); 
          $("#spnClose").bind("click", function(){
          $("#colorpanel").css("display","none"); }
          ); 
  } 
           
  //鼠标覆盖事件 
  function doOver(event) { 
      var e = $.event.fix(event); 
      var element = e.target; 
      if ((element.tagName == "TD") && (current != element)) { 
   
          if (current != null) { current.style.backgroundColor = current.style.background; } 
          element.style.background = element.style.backgroundColor; 
          $("#DisColor").css("backgroundColor", 
          element.style.backgroundColor); 
          var clr = element.style.backgroundColor.toUpperCase(); 
          if (clr.indexOf('RGB') > -1) { 
              clr = clr.substring(clr.length - 18); 
              clr = rgb2hex(clr); 
          } 
          $("#HexColor").val(clr); 
          //element.style.backgroundColor = "white"; 
          current = element; 
      } 
  } 
          //鼠标移开事件 
          function doOut(event) { 
              if (current != null) current.style.backgroundColor = 
          current.style.background.toUpperCase(); 
          } 
          //鼠标点击事件 
          function doclick(event) { 
              var e = $.event.fix(event); 
              if (e.target.tagName == "TD") {    var clr = e.target.style.background; 
              clr = clr.toUpperCase(); 
              if (targetElement) { 
                  if (clr.indexOf('RGB') > -1) { 
                      clr = clr.substring(clr.length - 18); 
                      clr = rgb2hex(clr); 
                  } 
                  targetElement.value = clr;  
              } 
              DisplayClrDlg(false, e); 
              return clr; 
          } 
      } 
       
      var targetElement = null; 
       
      function OnDocumentClick(event) { 
       
          var e = $.event.fix(event); 
          var srcElement = e.target; 
//         if (srcElement.alt == "clrDlg") { 
          targetElement = srcElement; 
          DisplayClrDlg(true, e); 
//       } 
//       else { 
   
//           while (srcElement && srcElement.id != "colorpanel") { 
//               srcElement = srcElement.parentElement; 
//           } 
//           if (!srcElement) { 
//               DisplayClrDlg(false, e); 
//           } 
//       } 
  } 
   
  //显示颜色对话框 
  //display 决定显示还是隐藏 
  //自动确定显示位置 
  function DisplayClrDlg(display, event) { 
  var clrPanel = $("#colorpanel"); 
   if (display) {
       var left = document.body.scrollLeft + event.clientX; 
       var top = document.body.scrollTop + event.clientY; 
       if (event.clientX + clrPanel.width > document.body.clientWidth) { 
           //对话框显示在鼠标右方时会出现遮挡将其显示在鼠标左方 
           left -= clrPanel.width; 
       } 
       if (event.clientY + clrPanel.height > document.body.clientHeight) { 
           //对话框显示在鼠标下方时会出现遮挡将其显示在鼠标上方 
           top -= clrPanel.height; 
       } 
       clrPanel.css("left", left); 
       clrPanel.css("top", top); 
       clrPanel.css("display", "block"); 
   } else { 
       clrPanel.css("display", "none"); 
   } 

  
//RGB转十六进制颜色值 
  function zero_fill_hex(num, digits) { 
      var s = num.toString(16); 
      while (s.length < digits) 
          s = "0" + s; 
      return s; 
  } 
   
  function rgb2hex(rgb) { 
      if (rgb.charAt(0) == '#') 
          return rgb; 
      var n = Number(rgb); 
      var ds = rgb.split(/\D+/); 
      var decimal = Number(ds[1]) * 65536 + Number(ds[2]) * 256 + Number(ds[3]); 
      return "#" + zero_fill_hex(decimal, 6); 
  }

这篇关于jsp页面引入调色板、颜色表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1003280

相关文章

在React中引入Tailwind CSS的完整指南

《在React中引入TailwindCSS的完整指南》在现代前端开发中,使用UI库可以显著提高开发效率,TailwindCSS是一个功能类优先的CSS框架,本文将详细介绍如何在Reac... 目录前言一、Tailwind css 简介二、创建 React 项目使用 Create React App 创建项目

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤

一文教你Python引入其他文件夹下的.py文件

《一文教你Python引入其他文件夹下的.py文件》这篇文章主要为大家详细介绍了如何在Python中引入其他文件夹里的.py文件,并探讨几种常见的实现方式,有需要的小伙伴可以根据需求进行选择... 目录1. 使用sys.path动态添加路径2. 使用相对导入(适用于包结构)3. 使用pythonPATH环境

Android WebView无法加载H5页面的常见问题和解决方法

《AndroidWebView无法加载H5页面的常见问题和解决方法》AndroidWebView是一种视图组件,使得Android应用能够显示网页内容,它基于Chromium,具备现代浏览器的许多功... 目录1. WebView 简介2. 常见问题3. 网络权限设置4. 启用 JavaScript5. D

Flutter监听当前页面可见与隐藏状态的代码详解

《Flutter监听当前页面可见与隐藏状态的代码详解》文章介绍了如何在Flutter中使用路由观察者来监听应用进入前台或后台状态以及页面的显示和隐藏,并通过代码示例讲解的非常详细,需要的朋友可以参考下... flutter 可以监听 app 进入前台还是后台状态,也可以监听当http://www.cppcn

MySQL表锁、页面锁和行锁的作用及其优缺点对比分析

《MySQL表锁、页面锁和行锁的作用及其优缺点对比分析》MySQL中的表锁、页面锁和行锁各有特点,适用于不同的场景,表锁锁定整个表,适用于批量操作和MyISAM存储引擎,页面锁锁定数据页,适用于旧版本... 目录1. 表锁(Table Lock)2. 页面锁(Page Lock)3. 行锁(Row Lock

禁止HTML页面滚动的操作方法

《禁止HTML页面滚动的操作方法》:本文主要介绍了三种禁止HTML页面滚动的方法:通过CSS的overflow属性、使用JavaScript的滚动事件监听器以及使用CSS的position:fixed属性,每种方法都有其适用场景和优缺点,详细内容请阅读本文,希望能对你有所帮助... 在前端开发中,禁止htm

使用JavaScript将PDF页面中的标注扁平化的操作指南

《使用JavaScript将PDF页面中的标注扁平化的操作指南》扁平化(flatten)操作可以将标注作为矢量图形包含在PDF页面的内容中,使其不可编辑,DynamsoftDocumentViewer... 目录使用Dynamsoft Document Viewer打开一个PDF文件并启用标注添加功能扁平化

SpringBoot项目引入token设置方式

《SpringBoot项目引入token设置方式》本文详细介绍了JWT(JSONWebToken)的基本概念、结构、应用场景以及工作原理,通过动手实践,展示了如何在SpringBoot项目中实现JWT... 目录一. 先了解熟悉JWT(jsON Web Token)1. JSON Web Token是什么鬼

SpringBoot如何访问jsp页面

《SpringBoot如何访问jsp页面》本文介绍了如何在SpringBoot项目中进行Web开发,包括创建项目、配置文件、添加依赖、控制层修改、测试效果以及在IDEA中进行配置的详细步骤... 目录SpringBoot如何访问JSP页python面简介实现步骤1. 首先创建的项目一定要是web项目2. 在