当前位置导航:炫浪网>>网络学院>>网页制作>>JavaScript教程

网页特效--在页面上蠕动的怪圈

      <HTML><HEAD><META http-equiv='Content-Type' content='text/html; charset=gb2312'><TITLE>一个在页面上蠕动的怪圈,可以变换一下颜色,效果会好许多</TITLE></HEAD><BODY bgcolor=#000000><script language=JavaScript>if (document.all){with (document){write('<div id="starsDiv" style="position:absolute;top:0px;left:0px">')str = '<div style="position:relative;width:XXpx;height:XXpx;background:#ffffff;font-size:XXpx;visibility:visible"></div>'re = /XX/g;// 创建正则表达式模式?str1=str.replace(re,"1")str2=str.replace(re,"2")str3=str.replace(re,"3")for (j=0;j<2;j++){ for (i=0;i<14;i++) write(str1) for (i=0;i<9;i++) write(str2)}write(str3)write('</div>')}}if (document.layers)var yBase = 10;var xBase = 10;var step = 0.5;var currStep = 0;var Xpos = 520;var Ypos = 250;if (document.all){  function MoveHandler(){  Xpos = document.body.scrollLeft+event.x;  Ypos = document.body.scrollTop+event.y;  }                ;}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></HTML>


<!-- 要实现此效果需要 2 个步骤: -->

<!-- 第 1 步: -->
<!-- 把<BODY>中的属性代码改为: -->

<BODY bgcolor=#000000>

<!-- 第 2 步: -->
<!-- 把下面的代码加到<BODY></BODY>区域中: -->

<script language=JavaScript>

if (document.all){
with (document){
write('<div id="starsDiv" style="position:absolute;top:0px;left:0px">')
str = '<div style="position:relative;width:XXpx;height:XXpx;background:#ffffff;font-size:XXpx;visibility:visible"></div>'
re = /XX/g;// 创建正则表达式模式?
str1=str.replace(re,"1")
str2=str.replace(re,"2")
str3=str.replace(re,"3")
for (j=0;j<2;j++)
{
for (i=0;i<14;i++)
write(str1)

for (i=0;i<9;i++)
write(str2)
}
write(str3)
write('</div>')
}
}

if (document.layers)

var yBase = 10;
var xBase = 10;
var step = 0.5;
var currStep = 0;
var Xpos = 520;
var Ypos = 250;

if (document.all)
{
function MoveHandler(){
Xpos = document.body.scrollLeft+event.x;
Ypos = document.body.scrollTop+event.y;
}
;
}

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>

 

相关内容
赞助商链接