| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 790 人关注过本帖
标题:js新手 发一个刚弄的配色板
只看楼主 加入收藏
myfor
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:357
专家分:6
注 册:2006-3-13
收藏
 问题点数:0 回复次数:1 
js新手 发一个刚弄的配色板

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>取色</title>
<style type="text/css"><!--
body { width:90%;font-size:12px; color:#000000; font-family: Georgia, Arial; margin: 20px;}
td { border-top:1px solid #000000; }
div {float:left;}
.border { border:1px solid #000000; width:255px; }
.red,.green,.blue { border:none; width:0px;}
.red { background: red;}
.green { background: green;}
.blue { background: blue;}
#show { background:#000000;width:100px;}
--></style>
<script type="text/javascript">
function color(obj, onobj)
{
var e = window.event ? window.event : color.caller.arguments[0];
var oo = document.getElementById(obj);
var widthpx = e.clientX - fetchOffset(oo) >= 0 ? (e.clientX - fetchOffset(oo) <= 255 ? e.clientX - fetchOffset(oo) : 255) : 0;
oo.style.width = widthpx + 'px';
onobj.onmousemove = function()
{
color(obj, onobj);
}
onobj.onmouseup = function()
{
onobj.onmousemove = null;
};
showcolor();
}
function showcolor()
{
var vred = 0;
if(parseInt(document.getElementById('red').style.width.replace('px', ''))!='NaN')
{
vred = parseInt(document.getElementById('red').style.width.replace('px', ''));
}
var vgreen = 0;
if(parseInt(document.getElementById('green').style.width.replace('px', ''))!='NaN')
{
vgreen = parseInt(document.getElementById('green').style.width.replace('px', ''));
}
var vblue = 0;
if(parseInt(document.getElementById('blue').style.width.replace('px', ''))!='NaN')
{
vblue = parseInt(document.getElementById('blue').style.width.replace('px', ''));
}
var value = '#' + tohex(vred) + tohex(vgreen) + tohex(vblue);
document.getElementById('show').style.background = value;
document.getElementById('code').value = value;
}
function tohex(inv)
{
var hex = inv.toString(16);
if(hex=='NaN')
hex = '00';
if(hex.length < 2)
hex = '0' + hex;
return hex;
}
function fetchOffset(obj) {
var left_offset = obj.offsetLeft;
while((obj = obj.offsetParent) != null) {
left_offset += obj.offsetLeft;
}
return left_offset;
}
</script>
</head>
<body>
<table cellspacing="1" cellpadding="1" style="border:1px solid #000000;width:360px;" align="center">
<tr><td colspan="2">调色</td></tr>
<tr><td><div class="border" onmousedown="color('red', this);"><div class="red" id="red" onmousedown="color('red', this);">&nbsp;</div></div></td><td rowspan="3" id="show">&nbsp;</td></tr>
<tr><td><div class="border" onmousedown="color('green', this);"><div class="green" id="green" onmousedown="color('green', this);">&nbsp;</div></div></td></tr>
<tr><td><div class="border" onmousedown="color('blue', this);"><div class="blue" id="blue" onmousedown="color('blue', this);">&nbsp;</div></div></td></tr>
<tr><td colspan="2">颜色代码:<input type="text" style="width:100px;" id="code" value="#000000" /></td></tr>
</table>
</body>
</html>

[此贴子已经被作者于2007-8-21 9:01:45编辑过]

搜索更多相关主题的帖子: 配色 
2007-08-21 09:00
VB爱上我
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:478
专家分:52
注 册:2005-10-14
收藏
得分:0 
好东西!!

IT618资讯网 提供服务端开发,前端开发,网页特效,热门开源系统研究,软件下载,站长建站,淘宝开店等学习资料.
2007-08-23 10:26
快速回复:js新手 发一个刚弄的配色板
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015796 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved