jquery.colorpicker.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var ColorHex=new Array('00','33','66','99','CC','FF');
  2. var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF');
  3. $(function(){
  4. initColor();
  5. $("#colorpanel").hide();
  6. })
  7. function initColor(){
  8. $("body").append('<div id="colorpanel" style="position: absolute; display: none;"></div>');
  9. var colorTable='';
  10. for(i=0;i<2;i++){
  11. for(j=0;j<6;j++){
  12. colorTable=colorTable+'<tr height=12>'
  13. colorTable=colorTable+'<td width=11 style="background-color:#000000">'
  14. if (i==0){
  15. colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[j]+ColorHex[j]+ColorHex[j]+'">'
  16. }else{
  17. colorTable=colorTable+'<td width=11 style="background-color:#'+SpColorHex[j]+'">'
  18. }
  19. colorTable=colorTable+'<td width=11 style="background-color:#000000">'
  20. for (k=0;k<3;k++){
  21. for (l=0;l<6;l++){
  22. colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[k+i*3]+ColorHex[l]+ColorHex[j]+'">'
  23. }
  24. }
  25. }
  26. }
  27. colorTable='<table width=253 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse" bordercolor="000000">'
  28. +'<tr height=30><td colspan=21 bgcolor=#cccccc>'
  29. +'<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">'
  30. +'<tr><td width="3"><td><input type="text" id="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>'
  31. +'<td width="3"><td><input type="text" id="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"><a href=### id="_cclose">关闭</a> <a href=### id="_clean">清除设置</a></td></tr></table></td></table>'
  32. +'<table id="CT" border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" style="cursor:pointer;">'
  33. +colorTable+'</table>';
  34. $("#colorpanel").html(colorTable);
  35. }
  36. function showColorPanel(obj,txtobj){
  37. $('#'+obj).click(function(){
  38. //定位
  39. var ttop = $(this).offset().top; //控件的定位点高
  40. var thei = $(this).height(); //控件本身的高
  41. var tleft = $(this).offset().left; //控件的定位点宽
  42. $("#colorpanel").css({
  43. top:ttop+thei+5,
  44. left:tleft
  45. })
  46. $("#colorpanel").show();
  47. $("#CT tr td").unbind("click").mouseover(function(){
  48. var aaa=$(this).css("background-color");
  49. $("#DisColor").css("background-color",aaa);
  50. $("#HexColor").val(aaa);
  51. }).click(function(){
  52. var aaa=$(this).css("background-color");
  53. $('#'+obj).css("background-color",aaa);
  54. $('#'+txtobj).val(aaa).css("color",aaa);
  55. $("#colorpanel").hide();
  56. })
  57. $("#_clean").click(function(){
  58. $("#colorpanel").hide();
  59. $('#'+obj).css("background-color",'');
  60. $('#'+txtobj).val('').css("color",'');
  61. })
  62. $("#_cclose").click(function(){$("#colorpanel").hide();}).css({"font-size":"12px","padding-left":"20px"})
  63. })
  64. }
  65. jQuery.extend({
  66. showcolor:function(btnid,txtid){showColorPanel(btnid,txtid); }
  67. })