设为首页
加入收藏
站内地图
旧版入口

跟随鼠标的旋转星星代码特效

作者:佚名 出处:网络转载 时间:10-18 点击:

内容载入中...
   说明: 
这代码必须放在<body>内 
其中,每一行write(’<div style="position:relative;width:1px;height:1px;background:#6699CC;font-size:1px;visibility:visible"></div>’)就代表一只小星星;其间的font-size:1px代表小星星的大小,background:#6699CC代表小星星的颜色;而前面的width:1px;height:1px则分别代表小星星的宽和高。你可以自已试着改变它们的具体属性和星星的数量。
--------------------------------------------------------------------------------
以下内容为程序代码:
<body>
<script language=javascript> 
if (document.all){ 
with (document){ 
write(’<div id="starsDiv" style="position:absolute;top:0px;left:0px">’) 
write(’<div style="position:relative;width:1px;height:1px;background:#ff99CC;font-size:1px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:1px;height:1px;background:#0099CC;font-size:1px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:1px;height:1px;background:#6699ff;font-size:1px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:1px;height:1px;background:#66ffCC;font-size:1px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:1px;height:1px;background:#33ffCC;font-size:1px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:1px;height:1px;background:#663300;font-size:1px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:1px;height:1px;background:#0011ff;font-size:1px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:2px;height:2px;background:#CC99CC;font-size:2px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:2px;height:2px;background:#999999;font-size:2px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:2px;height:2px;background:#663333;font-size:2px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:2px;height:2px;background:#00CCCC;font-size:2px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:2px;height:2px;background:#6600CC;font-size:2px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:2px;height:2px;background:#6633CC;font-size:2px;visibility:visible"></div>’) 
write(’<div style="position:relative;width:3px;height:3px;background:#6FF9C0;font-size:3px;visibility:visible"></div>’) 
write(’</div>’) } } 
if (document.layers) 
{window.captureEvents(Event.MOUSEMOVE);} 
var yBase = 200; 
var xBase = 200; 
var step = 1; 
var currStep = 0; 
var Xpos = 1; 
var Ypos = 1; 
if (document.all) 
{ function MoveHandler(){Xpos = document.body.scrollLeft+event.x; Ypos = document.body.scrollTop+event.y; } 
document.onmousemove = MoveHandler; } 
else if (document.layers) 
{ function xMoveHandler(evnt)
{ Xpos = evnt.pageX; Ypos = evnt.pageY; } 
window.onMouseMove = xMoveHandler; } 
function animateLogo() { 
if (document.all) { 
yBase = window.document.body.offsetHeight/6; 
xBase = window.document.body.offsetWidth/6; } 
else if (document.layers) 
{ yBase = window.innerHeight/8; xBase = window.innerWidth/8; } 
if (document.all) 
{ for ( i = 0 ; i < starsDiv.all.length ; i++ ) 
{ starsDiv.all[i].style.top = Ypos + yBase*Math.sin((currStep + i*4)/12)*Math.cos(400+currStep/200); 
starsDiv.all[i].style.left = Xpos + xBase*Math.sin((currStep + i*3)/10)*Math.sin(currStep/200); 
} } 
else if (document.layers) 
{ for ( j = 0 ; j < 14 ; j++ ) //number of NS layers! 
{ var templayer="a"+j 
document.layers[templayer].top = Ypos + yBase*Math.sin((currStep + j*4)/12)*Math.cos(400+currStep/200); 
document.layers[templayer].left = Xpos + xBase*Math.sin((currStep + j*3)/10)*Math.sin(currStep/200); 
} } 
currStep+= step; 
setTimeout("animateLogo()", 10); } 
animateLogo(); 
</script>
</body>
收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口
推荐信息