javascript 实现 QQshow

============思路============
1、首先想到,在展示形象的div中,一定要将裤子、衣服、头发和头饰的图片分别放在不同的层(这可以用z-index标记)。因为头饰要盖住头发,头发要盖在衣服上,衣服的下沿也要盖住裤头。
2、各种衣物如何在div中定位?可以在制作图片时就定好位置,图片尺寸与div相同,该有东西的地方放上东西,程序中不须再处理。
3、如何穿脱衣服?可以在div中创建四个<img>,它们大小一样,但处于不同的层。分别装裤子、衣服、头发和头饰。当试穿衣物A时,就将相应img的src改为A的图片地址。这样原来穿着的衣服就自动没有了,不用再写脱衣服的函数,但如果原本就穿着衣物A,则要将相应的img的src改为初始时的图片。
4、3中提到的衣物A与相应的img如何联系起来呢?可以将衣物抽象为Clothes类,它有layer属性和image属性和putOn()方法。
trousers,jacket,hair,headwear是它的实例,这样,如果需要换裤子,则调用trousers.putOn("A"),函数就会去修改对应于裤子的img。
============说明=============
程序中没有写“保存形象”的方法,如果要保存形象,需要form提交相关数据到服务器端,服务器端将结果保存在数据库中,这样的话下次浏

览该页面或刷新该页面的的时候读取数据库中的信息,然后就可以看到新的形象了。
============代码=============

<!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=gb2312" /> <title> QQ show </title> <style type="text/css"><!-- #bodyshow{ border:1px solid #000000; padding:0; position:relative; left:0; top:0; height:226px; width:140px; } .wrap{ border:0; background-color:#eee; } img{ height:84px; width:84px; border:0; } --></style> </head> <body> <div id="bodyshow"></div> <form name="equipform" method="post" action=""> <input name="saveequip" type="submit" value="保存形象" /> <input name="toreequip" type="button" value="原始形象" οnclick="init();" /> </form> <table class="wrap" cellspacing="0" cellpadding="0"> <colgroup width="84"></colgroup> <tr> <td><a href="javascript:void(0)" οnclick="headwear.putOn(1);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/4/1x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="headwear.putOn(2);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/4/2x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="headwear.putOn(3);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/4/3x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="headwear.putOn(4);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/4/4x.gif" /></a></td> </tr> <tr> <td><a href="javascript:void(0)" οnclick="hair.putOn(1);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/3/1x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="hair.putOn(2);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/3/2x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="hair.putOn(3);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/3/3x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="hair.putOn(4);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/3/4x.gif" /></a></td> </tr> <tr> <td><a href="javascript:void(0)" οnclick="jacket.putOn(1);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/2/1x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="jacket.putOn(2);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/2/2x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="jacket.putOn(3);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/2/3x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="jacket.putOn(4);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/2/4x.gif" /></a></td> </tr> <tr> <td><a href="javascript:void(0)" οnclick="trousers.putOn(1);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/1/1x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="trousers.putOn(2);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/1/2x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="trousers.putOn(3);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/1/3x.gif" /></a></td> <td><a href="javascript:void(0)" οnclick="trousers.putOn(4);"> <img src="http://www.pconline.com.cn/pcedu/redian/code_2003/equipment/1/4x.gif" /></a></td> </tr> </table> </body> <script type="text/javascript"><!-- var path = "http://www.pconline.com.cn/pcedu/redian/code_2003/equipment"; function Clothes(layer){// include jacket,trousers,hair,headwear this.layer = layer; var image = document.createElement("img"); image.src = ""; image.style.position = "absolute"; image.style.top = "0px"; image.style.left = "0px"; image.style.zIndex = this.layer; // in IE,if don't set 'width' and 'height',when the image is '1px*1px',things will go wrong. image.style.width = "140px"; image.style.height = "226px"; this.image = image; document.getElementById("bodyshow").appendChild(this.image); } Clothes.prototype.putOn = function (imgName){ if(this.image.src == path + "/" + this.layer + "/" + imgName + ".gif") { // replace the current image with the default image "df.gif" this.image.src = path + "/" + this.layer + "/" + "df.gif"; } else { this.image.src = path + "/" + this.layer + "/" + imgName + ".gif"; } } var headwear = new Clothes(4); var hair = new Clothes(3); var jacket = new Clothes(2); var trousers = new Clothes(1); function init(){ trousers.putOn("df"); jacket.putOn("df"); hair.putOn("df"); headwear.putOn("df"); } init(); // --></script> </html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值