注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

.

.

 
 
 

日志

 
 

背景颜色选择器代码  

2010-01-10 15:41:35|  分类: 博客技巧 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

背景颜色选择器

脚本说明:
把如下代码加入<body>区域中
<script language="JavaScript">
<!--

// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.geocities.com/~yehuda/

// create 6-element array
var hex = new Array(6)

// assign non-dithered descriptors
hex[0] = "FF"
hex[1] = "CC"
hex[2] = "99"
hex[3] = "66"
hex[4] = "33"
hex[5] = "00"

// accept triplet string and display as background color
function display(triplet) {
 // set color as background color
 document.bgColor = '#' + triplet

 // display the color hexadecimal triplet
 alert('现在的背景色是 #'+triplet)
}

// draw a single table cell based on all descriptors
function drawCell(red, green, blue) {
 // open cell with specified hexadecimal triplet background color
 document.write('<TD BGCOLOR="#' + red + green + blue + '">')

 // open a hypertext link with javascript: scheme to call display function
 document.write('<a href="javascript:display(\'' + (red + green + blue) + '\')">')

 // print transparent image (use any height and width)
 document.write('<IMG SRC="place.gif" BORDER=0 HEIGHT=12 WIDTH=12>')

 // close link tag
 document.write('</A>')

 // close table cell
 document.write('</TD>')
}

// draw table row based on red and blue descriptors
function drawRow(red, blue) {
 // open table row
 document.write('<TR>')

 // loop through all non-dithered color descripters as green hex
 for (var i = 0; i < 6; ++i) {
  drawCell(red, hex[i], blue)
 }

 // close current table row
 document.write('</TR>')
}

// draw table for one of six color cube panels
function drawTable(blue) {
 // open table (one of six cube panels)
 document.write('<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>')

 // loop through all non-dithered color descripters as red hex
 for (var i = 0; i < 6; ++i) {
  drawRow(hex[i], blue)
 }

 // close current table
 document.write('</TABLE>')
}

// draw all cube panels inside table cells
function drawCube() {
 // open table
 document.write('<TABLE CELLPADDING=5 CELLSPACING=0 BORDER=1><TR>')

 // loop through all non-dithered color descripters as blue hex
 for (var i = 0; i < 6; ++i) {
  // open table cell with white background color
  document.write('<TD BGCOLOR="#FFFFFF">')

  // call function to create cube panel with hex[i] blue hex
  drawTable(hex[i])

  // close current table cell
  document.write('</TD>')
 }

 // close table row and table
 document.write('</TR></TABLE>')
}

// call function to begin execution
drawCube()

// -->
</script>


 

  评论这张
 
阅读(202)| 评论(10)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017