JavaScript学习之自定义对象小游戏找不同颜色
来源:互联网 发布:数据不被单独保存 编辑:程序博客网 时间:2024/06/03 12:47
由于这个也是自定义对象写的代码,之前的博客中也有自定义对象方法,有详细的注释,这个就不再写注释了。
js代码:
<script type="text/javascript"> var Box; var Yuan; function box() { this.width = "500"; this.height = "500"; this.margin = "100px auto"; this._box = null; this.creatbox = function() { if(this._box == null) { this._box = document.createElement("div"); this._box.className="divbg"; this._box.style.width = this.width + "px"; this._box.style.height = this.height + "px"; this._box.style.margin = this.margin; document.body.appendChild(this._box); } } } function yuan() { this.borderradius = "50%"; this.float = "left"; this.creatyuan = function(count) { document.getElementsByClassName("divbg")[0].innerHTML=""; var backcolor = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")"; var num = Math.floor(Math.random() * (count * count)); for(i = 0; i < count * count; i++) { this._yuan = document.createElement("div"); this._yuan.style.width = 500 / count + "px"; this._yuan.style.height = 500 / count + "px"; this._yuan.style.backgroundColor = backcolor; this._yuan.style.borderRadius = this.borderradius; this._yuan.style.float = this.float; if(i == num) { this._yuan.style.opacity = 0.5; this._yuan.addEventListener("click", clickblock); } Box._box.appendChild(this._yuan); } } } function clickblock() { countnum++; Yuan.creatyuan(countnum); } var countnum = 3; window.onload = function() { Box = new box(); Box.creatbox(); Yuan = new yuan(); Yuan.creatyuan(countnum); } </script>
阅读全文
0 0
- JavaScript学习之自定义对象小游戏找不同颜色
- JavaScript学习之自定义对象--小游戏贪吃蛇
- JavaScript学习之自定义对象--小游戏别踩白块儿
- JavaScript学习之自定义对象
- JavaScript学习笔记之自定义对象
- JavaScript之自定义对象、事件
- JavaScript学习之对象
- unity学习之小游戏
- javascript之猜数小游戏
- Javascript基础学习(三)-自定义对象数组
- javascript之自定义数组工具对象
- javaScript系列之自定义对象(七)
- 自编Javascript小游戏-妞妞找妈妈
- JS 之 找对象
- javascript学习之面向对象
- javascript学习之对象继承
- javascript学习总结之(对象)
- javascript 学习之string对象
- 第十五天
- 神经网络的预训练
- jsp中name和id
- Spring的两种测试方式
- ubuntu17.04 UHD 驱动出错
- JavaScript学习之自定义对象小游戏找不同颜色
- Snmp的基本概念
- Java8--并行流
- 【C++】C++大数的运算
- Solr__luence(四)Analyzer分词器
- spring实战-Spring-Tiles模板的应用
- 《The clean coder》 读后总结
- C Primer Plus(第五版)中文版pdf
- Android之编译jni出错解决办法