============思路============
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>

javascript 实现 QQshow相关推荐

  1. 【AJAX】JavaScript的面向对象

    Ajax中后端数据返回后需要前端通过JavaScript来实现动态数据更新的问题.所以,在Ajax中加深了一遍JavaScript面向对象的印象. 基础部分: JavaScript中创建对象并简单对象 ...

  2. 【JavaScript总结】JavaScript语法基础:JS高级语法

    作用域链: 1.JS中只有函数能够限定作用域的范围: 2.变量处理在制定的函数范围内,还有一个特殊的作用域,就是没有用var 声明的全局作用域 3.js中的作用域链是为了清晰的表示出所有变量的作用范围 ...

  3. 【JavaScript总结】JavaScript语法基础:DOM

    ->DOM的理解:文档对应dom树 ->有了DOM能做什么:DOM的操作 html文档做为DOM树模型,DOM树的节点就是对象.对象会触发事件来执行一些事件代码. C#中的事件是一个委托变 ...

  4. 【JavaScript总结】JavaScript语法基础:JS编码

    运算符 数学:+. -. *. / 逻辑:>. < .>= .<=. == . !=.&&.|| . === .!==(完全等于) 对象相关 new delet ...

  5. 【JavaScript总结】JavaScript语法基础:数据类型

    ------>数据类型有哪些? ->基本类型:数字类型,布尔类型,字符串类型 ->引用类型:对象类型,函数类型 ->空类型:null 和 undefined ->运算符: ...

  6. 【JavaScript总结】JavaScript发展与学习内容

    发展: 最初浏览器是为大学里浏览文档用,从地址栏输入文档地址,找到文档显示. 后来各种需求(购物网站,个人博客)出现,已有功能不能满足需求. 可人们依旧在努力满足这种需求,但实现后的效果很不尽人意. ...

  7. Python:模拟登录、点击和执行 JavaScript 语句案例

    案例一:网站模拟登录 # douban.pyfrom selenium import webdriver from selenium.webdriver.common.keys import Keys ...

  8. [JavaScript] JavaScript数组挖掘,不只是讲数组哟(2)

    课程来源:后盾人 上一篇的内容:[JavaScript] JavaScript数组挖掘,不只是讲数组哟 数组引用类型分析,多维数组,用Array.of为数组创建细节,类型检测与转换,在一个数组后面加一 ...

  9. [JavaScript] JavaScript 数组挖掘,不只是讲数组哟

    课程来源:后盾人 数组引用类型分析 数组的定义 const array = new Array('hello', 'dust', 1, 2, 3, 4, 5) console.log(array) l ...

最新文章

  1. 瑞尔森大学的计算机科学专业,瑞尔森大学有哪些专业处于世界顶尖水平?
  2. Throwable、Error、Exception、RuntimeException 区别 联系
  3. js 字符串加减法_JavaScript (+) 加法运算符
  4. ARM平台YUV转RGB888(转)
  5. javax.naming.NameNotFoundException:
  6. 完整的Web应用程序Tomcat JSF Primefaces JPA Hibernate –第1部分
  7. Akka的字数统计MapReduce
  8. vue读取终端硬件信息_双通道RFID模块助力电力数据采集终端(不必多说,直接测试对比)...
  9. 数组作为方法的参数实例和细节(Java)
  10. AFNetworking 文件断点下载详细解读
  11. 2018年第一周APP黑马榜单
  12. 【能效管理】电力监控系统在某商业数据中心的应用分析
  13. AttacKG: Constructing Technique Knowledge Graph from Cyber Threat Intelligence Reports 源码复现
  14. [论文阅读笔记]Deep Neural Networks are Easily Fooled:High Confidence Predictions for Unrecognizable Images
  15. 30 个Python代码实现的常用功能(附案例源码)
  16. Android备份到电脑,用 TWRP「一键 Ghost」你的 Android 手机,还能备份到电脑
  17. php1蛋白质带电情况,结合蛋白质(1)
  18. 【ntp】Linux Windows时间服务器NTP配置
  19. Linux 解压tar.bz2格式文件
  20. 【origin绘图】如何通过插入小图的方法放大局部图

热门文章

  1. [词性] 十八、介词 8 [ within ] [ within ] [ across ] [ among ] [ outside ] [ into ] [ beyond ] [ against ]
  2. Kubernetes HPA测试
  3. HPA控制器介绍以及实战案例
  4. [ARM嵌入式系统开发]第一章之嵌入式系统的软硬件
  5. libgdx 处理加速传感器
  6. 微信小程序生态开发-组件注册
  7. 【图像去噪】基于matlab全变分算法图像去噪【含Matlab源码 626期】
  8. PCBA方案定制,开发腕式血压计方案
  9. GPS导航电文文件和观测值文件解读
  10. unity2D学习(10)创建敌人、为敌人编写简单的AI