<div class="htmlarea"><textarea id="runcode93587"> <title>星空效果_www.jb51.net</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css"> <!-- body{ margin:0px; padding:0px; } body,td{ font-size:9pt; } .star{ position:absolute; width:1px; height:1px; font-size:0px; background-color:#ffffff; } --> </style> <script type="text/javascript"> <!-- try{ var winSize = { width:document.documentElement.clientWidth, height:document.documentElement.clientHeight } var MooSky = function(options){ this.options = options; this.stars = new Array(); this.show = function(){ for(var i=0;i<this.options.num;i++){ var newStar = new MooStar({ container : this.options.container }); newStar.fly(); this.stars[i] = newStar; } } } var MooStar = function(options){ this.options = options; if(!!this.options.container){ this.container = document.getElementById(this.options.container); }else{ this.container = document.body; } this.baseSpeed = 10; var o = this; this.speed = Math.round(Math.random()*this.baseSpeed)+1; this.dom = document.createElement('DIV'); this.dom.className = 'star'; if(!!this.options.container){ var left = Math.round(Math.random()*this.container.offsetWidth-1); var top = Math.round(Math.random()*this.container.offsetHeight-1); this.dom.style.left = left+'px'; this.dom.style.top = top+'px'; this.container.appendChild(this.dom); }else{ this.dom.style.left = Math.random()*winSize.width-1+'px'; this.dom.style.top = Math.random()*winSize.height-1+'px'; document.body.appendChild(this.dom); } } MooStar.prototype.fly = function(){ if(this.dom.offsetLeft<0){ if(!!this.options.container){ var left = this.container.offsetWidth-1; var top = Math.round(Math.random()*this.container.offsetHeight)-1; this.dom.style.left = left+'px'; this.dom.style.top = top+'px'; }else{ this.dom.style.left = winSize.width-1+'px'; this.dom.style.top = Math.random()*winSize.height-1+'px'; } }else{ var left = this.dom.offsetLeft-this.speed; if(left<0) { this.speed = Math.round(Math.random()*this.baseSpeed)+1; if(!!this.options.container){ left = this.container.offsetWidth-1; var top = Math.random()*this.container.offsetHeight-1; this.dom.style.top = top+'px'; }else{ left = winSize.width-1; } } this.dom.style.left = left+'px'; var self = this; setTimeout(function(){self.fly()},this.speed); } } window.onload = function(){ var mooSky1 = new MooSky({ num:30, container : 'skyContainer1' //濡</script></textarea></div>