现在的位置: 首页 >> 网页设计 >> 网页特效 >> 图形特效模拟太空
添加时间:2005-11-9 来源: 网上转帖   作者: 佚名
图形特效模拟太空

说明: 模拟太空

效果: 点这里在新窗口中看效果!

代码:


<body bgcolor="black">
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
astropic = "earth.gif"; // location of YOUR astronaut image
var xval = new Array(); // holds star coordinates
var yval = new Array();
no = 100; // number of stars in the background
speed = 200; // speed
xp = 20 + 100 * Math.random();
yp = 20 + 100 * Math.random();
angle = 3.14 * Math.random(); // astronaut angle
xinc = 3 * Math.sin(angle);
yinc = 3;
ie = (document.all)? 1 : 0;
ns = (document.layers)? 1: 0;
if (ie) {
width = document.body.clientWidth;
height = document.body.clientHeight;
for (var i = 0; i <= no; i++) {
document.write("<div id=\"div" + i+ "\" style=\"color:white;");
document.write("position:absolute;left:100;\">.</div>");
}
document.write("<div id=\"diva\" style=\"position:absolute;\">");
document.write("<img src=" + astropic + " border=\"0\" width=\"100\" height=\"100\"></div>");
for (i = 0; i <= no; i++) {
xval[i] = width * Math.random();
yval[i] = height * Math.random();
document.all["div" + i].style.left = xval[i];
document.all["div" + i].style.top = yval[i];
}
}
if (ns) {
width = self.innerWidth;
height = self.innerHeight;
for (var i = 0; i <= no; i++) {
document.write("<layer id=\"div" + i+ "\" style=\"color:white;");
document.write("position:absolute;left:100;\">.</layer>");
}
document.write("<layer id=\"diva\" style=\"position:absolute;\">");
document.write("<img src=" + astropic + " border=\"0\" width=\"100\" height=\"100\"></layer>");
for (i = 0; i <= no; i++) {
xval[i] = width * Math.random();
yval[i] = height * Math.random();
document.layers["div" + i].left = xval[i];
document.layers["div" + i].top = yval[i];
}
}
function star() {
for (i = 0; i <= no; i = i+4) {
xval[i] +=5;
if ((i%20) == 0) xval[i] += 10;
if(xval[i] >= width) xval[i] = width * Math.random();
if (ie) document.all["div" + i].style.left = xval[i];
if (ns) document.layers["div" + i].left = xval[i];
}
return true;
}
function goangle() {
angle = 3.14 * Math.random();
xinc = 3 * Math.sin(angle);
return true;
}
function space() {
if (ie) {
document.all["diva"].style.left = xp;
document.all["diva"].style.top = yp;
}
if (ns) {
document.layers["diva"].left = xp;
document.layers["diva"].top = yp;
}
xp += xinc;
yp +=yinc;
star();
if ((xp >= (width - 50)) || (xp <= 10)) { goangle(); xinc = (-1) * xinc; }
if ((yp >= (height - 50)) || (yp <= 10)) { goangle(); yinc = (-1) * yinc; }
setTimeout('space()', speed);
}
space();
// End -->
</script>



[1] [2]  下一页


上一篇:_滚动的文字说明_ 下一篇:图形特效鼠标停在文本上图片自动围绕
大部分文章摘自网上,如有侵犯您的权益请与我们联系,我们会第一时间进行处理,谢谢! [ 打印文章 ] [ 关闭窗口 ]
推荐文章
 
相关文章
·图形特效鼠标停在文本上图片自动
·图形特效将图片固定在右下角
·图形特效将图片固定在右上角
·图形特效将图片固定在左下角
·图形特效简单的对联广告代码
·图形特效对联广告代码效果之三[]
·图形特效对联广告代码效果之二[]
·图形特效对联广告代码效果之一[]
·图形特效QQ在线留言
·图形特效浮在页面上的图片广告
最新文章
·加入收藏夹
·利用全屏打开加重定窗口大小产生
·设为首页
·去掉超链接的下划线
·自动刷新网页
·刷新本页
·返回到上一页
·跳出小窗口
·自动关闭窗口
·给页面加保护
Google