【编程游戏】贺岁放礼花。(点燃续帖2-147楼xiuyouxu的焰火)(请在IE下运行)...

<script type="text/javascript"><!-- function viewPage(html) { var page = window.open('', '', ''); page.opener = null; page.document.write(html); page.document.close(); } window.onload = function() { var iframe = document.createElement("iframe"); iframe.width = "100%"; iframe.height = "400px"; iframe.frameBorder = "0"; iframe.marginHeight = "0"; iframe.src = "http://vote.csdn.net/VotePostSimple.aspx?voteid=994"; iframe.scrolling = "no"; var textarea = document.getElementsByTagName('textarea')[0]; textarea.parentNode.insertBefore(iframe, textarea); } // --></script>【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者:avatar
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] <html> <body bgcolor='#000000'> <script type="text/javascript"> base = { config : function(o, c) { for (var i in c) { o[i] = c[i]; } }, get : function(id) { return document.getElementById(id); }, createDiv : function(divId) { var obj = document.createElement('div'); obj.setAttribute('id', divId); return obj; }, getCssText : function(id) { if (typeof id == 'string') { var node = this.get(id); return node.style.cssText; } else { return id.style.cssText } }, setCssText : function(id, style) { if (typeof id == 'string') this.get(id).style.cssText = style; else id.style.cssText = style }, replaceSubstring : function(str, substr, newstr) { var b = str.indexOf(substr); var e = b + substr.length; var l = str.substring(0, b); var r = (e + 1) < str.length ? str.substring(e, str.length) : ''; return l + newstr + r; }, changeStyleByProperty : function(oldstyle, prop, newValue) { var b = oldstyle.indexOf(prop); var e = oldstyle.indexOf(';', b); var bc = oldstyle.substring(b, e + 1); var ns = prop + ':' + newValue + ';' return this.replaceSubstring(oldstyle, bc, ns); } } pongpong = function(c) { base.config(this, c); this.ball = ['○', '●', '★', '■', '◆', '▲']; this.g = 1; this.color = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink']; // this.x = Math.floor(document.body.clientWidth / 2); this.y = document.body.clientHeight - 40; this.maxHeight = document.body.clientHeight - 50; this.maxInitialV = Math.floor(Math.sqrt(2 * this.g * this.maxHeight)); this.minInitialV = Math.floor(Math .sqrt(2 * this.g * this.maxHeight * 2 / 3)); this.riv = 0; this.wd = document.body.clientWidth; this.initialStyle = "position:absolute;left:" + this.x + "px;top:" + this.y + "px;width:20px;height:20px;"; this.explodeColor = null; this.temp = null; this.init(); } pongpong.prototype = { x : Math.floor(document.body.clientWidth / 2), getRiv : function() { var r = Math.floor(Math.random() * this.maxInitialV); var m = this.maxInitialV - this.minInitialV; if (r < this.minInitialV) r = this.minInitialV + r % m; return r; }, init : function() { this.temp = base.createDiv('ball'); this.changeColor(); }, randomColor : function() { return this.color[Math.floor(Math.random() * 7)]; }, changeColor : function() { // 设置焰火颜色 this.explodeColor = this.randomColor(); this.setInnerHTML(this.temp, this.explodeColor); }, setInnerHTML : function(el, color) { el.innerHTML = ' <span style="color:' + color + ';">' + this.ball[Math.floor(Math.random() * 6)] + ' </span>' }, explode : function() { var left = this.temp.offsetLeft; var top = this.temp.offsetTop; document.body.removeChild(this.temp); document.body.style.backgroundColor = this.explodeColor; setTimeout(function() { document.body.style.backgroundColor = 'black'; }, 50); var nt = this; // 显示爆炸效果 var flag = true; // 碎片数 var sp = Math.floor(Math.random() * 6) + 1; var t = setInterval(function() { if (flag) { flag = false; for (var i = 0; i < sp; i++) { var spi = document.getElementById('sp' + i); spi = spi ? spi : base.createDiv('sp' + i); nt.setInnerHTML(spi, nt.randomColor()); var ix = left + (30 - Math.floor(Math.random() * 60)); var iy = top + (30 - Math.floor(Math.random() * 60)); var is = "position:absolute;left:" + ix + "px;top:" + iy + "px;width:20px;height:20px;"; document.body.appendChild(spi); base.setCssText(spi, is); } } else { for (var i = 0; i < sp; i++) { var si = document.getElementById('sp' + i); if (si) document.body.removeChild(si); } clearInterval(t); } }, 100); this.changeColor(); }, start : function() { this.riv = this.getRiv(); document.body.appendChild(this.temp); var x = Math.floor(this.wd / 4 + Math.random() * this.wd / 2) + 'px'; var ns = base.changeStyleByProperty(this.initialStyle, 'left', x); base.setCssText(this.temp, ns); var time = 0; var nt = this; var t = setInterval(function() { time = time + 1; var s = (nt.riv - nt.g * time / 2) * time; var v = nt.riv - nt.g * time; if (v >= 0) { var nh = nt.y - s; var ns = base.changeStyleByProperty(base.getCssText('ball'), 'TOP', nh); base.setCssText(nt.temp, ns); } else { clearInterval(t); nt.explode(); nt.start(); } }, 50); } } window.onload = function() { var pp = new pongpong(); pp.start(); } </script> </body> </html>
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值