简单javascript脚本游戏
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
window.onload=function(){
var bd=document.getElementsByTagName("body")[0];
bd.id="bd";
creatlay("mainlay","bd",300,400,100,50,"#66CCFF",0);
creatlay("mouselay","mainlay",50,20,0,380,"#53FD22",1);
creatlay("movelay","mainlay",20,20,0,360,"red",1);
var mainlay=document.getElementById("mainlay");
var mouselay=document.getElementById("mouselay");
var movelay=document.getElementById("movelay");
//creatlay("mo","mainlay",20,20,0,0,"red",1);
var x;
var y;
document.onmousemove=function(){
x=event.clientX;
y=event.clientY;
if(x x=mainlay.style.pixelLeft;}if(x>mainlay.style.pixelLeft+mainlay.style.pixelWidth-mouselay.style.pixelWidth){ x=mainlay.style.pixelLeft+mainlay.style.pixelWidth-mouselay.style.pixelWidth;} mouselay.style.pixelLeft=x-mainlay.style.pixelLeft;}var s=5; var xin; var yin; var remove=function(){ var x1=movelay.style.pixelLeft; var y1=movelay.style.pixelTop; if(x1<=0){ xin=true;}if(x1>=mainlay.style.pixelWidth-movelay.style.pixelWidth){ xin=false;}if(y1<=0){ yin=true;}if(y1>=mouselay.style.pixelTop- movelay.style.pixelHeight&&x1>=mouselay.style.pixelLeft&&(x1<=mouselay.style.pix elLeft+50)){ yin=false;}x1=x1+(xin?s: -s); y1=y1+(yin?s: -s); movelay.style.pixelLeft=x1; movelay.style.pixelTop=y1; if(y1>mouselay.style.pixelTop-movelay.style.pixelHeight){ movelay.style.pixelLeft=0; movelay.style.pixelTop=360;}} setInterval(remove,10);}// function crefloor(){}//生成布局层需要参数id: 目标id,生成层的位置;w: 层宽度;h: 层高度;pl: pixelLeft,与目标的左边距;pt: pixelTop与目标的上边距;c: color,层背景色;z: z-index,层序;var lay=0; function creatlay(layid,targetid,w,h,pl,pt,c,z){ document.getElementById(targetid).innerHTML=document.getElementById(targ etid).innerHTML+"
var lay=document.getElementById(layid);
lay.style.position="absolute";
lay.style.width=w;
lay.style.height=h;
lay.style.pixelLeft=pl;
lay.style.pixelTop=pt;
lay.style.backgroundColor=c;
lay.style.zIndex=z;}