Use JS to write the stars

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Star Effect _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 = this;
Xywtimeout (function () {self.fly ()},this.speed);
}
}
Window.xywxff = function () {
var mooSky1 = new Moosky ({
Num:30,
Container: ' SkyContainer1 '//If container is not declared, it is for document.body implementation
});
Moosky1.show ();
var mooSky2 = new Moosky ({
NUM:20,
Container: ' SkyContainer2 '
});
Moosky2.show ();
/*
This is for the body.
var mooSky3 = new Moosky ({
Num:20
});
Moosky3.show ();
*/
}
Window.onresize = function () {
Winsize = {
Width:document.documentElement.clientWidth,
Height:document.documentElement.clientHeight
}
}
}catch (e) {
alert (e.description);
}
-
</script>
<body scroll=no bgcolor= #000000 >
<div id= ' skyContainer1 ' style= "Height:100px;background-color: #222222; overflow:hidden;font-size:70px;color:# Ffff00;font-weight:bolder ">ABCD</div>
<div id= ' skyContainer2 ' style= "position:absolute;left:200px;top:200px;width:500px;height:100px; Background-color: #222222; " ></div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.