首页 | 代码中心 | 源码下载 | 用户管理 | 用户留言 | 导航 | 繁體
代码秀,专业程序代码提供商(源码下载,编程技术)
要完成此效果需要两个步骤 第一步:把如下代码加入到区域中 <Script LANGUAGE="JavaScript"> <-- var starnum = 75; // 星星的数目 var isNS = (document.layers); var _all = (isNS)? '' : 'all.'; var _style = (isNS) ? '' : '.style'; var xoffset, yoffset, w_x, w_y, tmpx, tmpy, scrlx, scrly; function getstartpos(obj) { //定义星星移动 的起始位置 obj.deltay = Math.floor(Math.random() * 12); //用随机函数决定 obj.deltax = Math.floor(Math.random() * 12); obj.xdir = (Math.floor(Math.random() * 2) == 1) ? '+' : '-'; o bj.ydir = (Math.floor(Math.random() * 2) == 1) ? '+' : '-'; obj.counter = 1; if (isNS) { o bj.clip.width = 1; obj.clip.height = 1; obj.moveTo(xoffset+pageXOffset, yoffset+pageYOffset); } else { obj.width = 1; obj.height = 1; obj.pixelTop = yoffset+document.body.scrollTop; o bj.pixelLeft = xoffset+document.body.scrollLeft; } } function movestar(starN) //移动星星的位 置 { tmpx = starN.deltax*starN.counter+starN.counter; tmpy = starN.deltay*starN.counter+starN.counter; if (isNS) { starN.clip.width = starN.counter / 3; s tarN.clip.height = starN.counter / 3; scrlx = pageXOffset; scrly = pageYOffset; if ((starN.left+tmpx >= w_x+scrlx) || (starN.top+tmpy >= w_y+scrly) || (starN.left-tmpx <= scrlx) || (starN.top-tmpy <= scrly)) { getstartpos(starN); } else { eval('starN.moveBy('+starN.xdir+tmpx+', '+starN.ydir+tmpy+')'); } } else { starN.width = starN.counter/3; starN.height = starN.counter/3; scrlx = document.body.scrollLeft; scrly = document.body.scrollTop; if ((starN.pixelLeft+tmpx >= w_x+scrlx)||(starN.pixelTop+tmpy >= w_y+scrly) || (starN.pixelLeft-tmpx <= scrlx)||(starN.pixelTop-tmpy <= scrly)) { getstartpos(starN); } else { e val('starN.pixelTop'+starN.ydir+'=tmpy'); eval('starN.pixelLeft'+starN.xdir+'=tmpx'); } } s tarN.counter++; } function animate() //让所有的星星动起来 { for(i=1; i <= starnum; i++) { m ovestar(eval('star'+i)); } setTimeout('animate()', 100); } function findwindowparams() { //定义 星星移动的起始位置 w_x = (isNS) ? window.innerWidth : document.body.clientWidth; w_y = (isNS) ? window.innerHeight : document.body.clientHeight; xoffset = w_x / 2; yoffset = w_y / 2; for (i = 1; i <= starnum; i++) { getstartpos(eval('star'+i)); } } function resizeNS() { s etTimeout('document.location.reload()', 400); } (isNS) ? window.onresize = resizeNS : window.onresize = findwindowparams; window.onload = new Function("findwindowparams(); animate();"); --> </Script> 第二步:把如下代码加入到区域中 <Script LANGUAGE="JavaScript"> <-- for (i = 1; i <= starnum; i++) { //给星星定义层 d ocument.writeln(''); eval('var star'+i+'=document.'+_all+'star'+i+_style); } --> </Script> 特别说明:如网页特效代码中有引用图片文件等,请自己下载到本地调试!