plane:function(oGameBox,e){???????????? var x=e.pageX,?????????????????????y=e.pageY;//鼠標到瀏覽器的距離????????????var oPlane=new Image();//獲取飛機圖片???????????? oPlane.src = 'img/plane.png';???????????? oPlane.width=60;???????????? oPlane.height=36;????????????var lx=oGameBox.offsetLeft+parseInt(oGameBox.style.borderWidth)+oPlane.width/2;???????????? var ty=oGameBox.offsetTop+parseInt(oGameBox.style.borderWidth)+oPlane.height/2; ???????????????????? var left=x-lx;???????????? var top=y-ty;???????????? oPlane.style.cssText="display:block;position:absolute;top:"+top+"px;left:"+left+"px;";//得到點擊之后,飛機在鼠標出的位置???????????? oGameBox.appendChild( oPlane );document.onmousemove=function(e){???????? e=e||window.event;???????? var top=e.pageY-ty;???????? var left=e.pageX-lx;???????? oPlane.style.top=top+'px';???????? oPlane.style.left=left+'px'; }
Js 中的 json pageX 和pageY,重復定義的原因是每移動一次就要重新獲取一次???
qq_唔叫咩_0
2018-05-14 16:47:41