Не работает OnMouseMove
Есть вот такой код:
var left=100,top=100; var x, y,x1; var jseyeimg="jseyeblue.gif"; var jseyesimg="jseyes.png"; var jseyeso=null, jseye1=null, jseye2=null; browsername = navigator.appName; if(browsername.indexOf("Netscape")!= -1) { browsername="NS"; } else { if(browsername.indexOf("Microsoft")!=-1) { browsername="MSIE"; } } function eyemove(x2,y2,a,b){ var tanteeta,opp,adj; var fx,fy; if (jseyeso && jseye1 && jseye2 && jseyeso.style) { if((x2 > a) && (y2> b)) { tanteeta=Math.atan((y2-b)/(x2-a)); opp=Math.round(Math.sin(tanteeta)*35*10000)/10000; adj=Math.round(Math.cos(tanteeta)*35*10000)/10000; fx=a+adj; fy=b+opp; if((x2<fx) && (y2<fy)) { fx=x2; fy=y2; } } if((x2 > a) && (y2< b)) { tanteeta=Math.atan((b-y2)/(x2-a)); opp=Math.round(Math.sin(tanteeta)*35*10000)/10000; adj=Math.round(Math.cos(tanteeta)*35*10000)/10000; fx=a+adj; fy=b-opp; if((x2<fx) && (y2>fy)) { fx=x2; fy=y2; } } if((x2 < a) && (y2< b)) { tanteeta=Math.atan((b-y2)/(a-x2)); opp=Math.round(Math.sin(tanteeta)*35*10000)/10000; adj=Math.round(Math.cos(tanteeta)*35*10000)/10000; fx=a-adj; fy=b-opp; if((x2>fx) && (y2>fy)) { fx=x2; fy=y2; } } if((x2 < a) && (y2> b)) { tanteeta=Math.atan((y2-b)/(a-x2)); opp=Math.round(Math.sin(tanteeta)*35*10000)/10000; adj=Math.round(Math.cos(tanteeta)*35*10000)/10000; fx=a-adj; fy=b+opp; if((x2>fx) && (y2<fy)) { fx=x2; fy=y2; } } var xx=new Array(); xx[0]=fx; xx[1]=fy; return xx; } } function jseyesmove(x2, y2) { var d =eyemove(x2,y2,x,y); jseye1.style.left=d[0]; jseye1.style.top=d[1]; var d =eyemove(x2,y2,x1,y); jseye2.style.left=d[0]; jseye2.style.top=d[1]; } function objects(id) { var x= document.getElementById(id); return(x); } function jseyes() { var img; x=left+35; x1=left+162; y=top+35; img= "<div id='jseyeslayer' style='position:absolute; left:45%; bottom:128px; '>"+ "<img src='"+jseyesimg+"' style='position:absolute; left:"+left+"; top:"+top+"; ' >"+ "<div id='jseye1' style='position:absolute; left:"+x+"; top:"+y+";width:30; height:30'>"+ "<img src='"+jseyeimg+"' width=30 height=30 >"+ "</div>"+"<div id='jseye2' style='position:absolute; left:"+x1+"; top:"+y+";width:30; height:30'>"+ "<img src='"+jseyeimg+"' width=30 height=30 >"+"</div>"+"</div>"; document.write(img); jseyeso=objects('jseyeslayer'); jseye1=objects('jseye1'); jseye2=objects('jseye2'); if(browsername=="NS") { document.captureEvents(Event.MOUSEMOVE); document.onmousemove=jseyesmousemoveNS; } else if(browsername=="MSIE") { document.onmousemove=jseyesmousemoveIE; } } function jseyesmousemoveNS(e) { jseyesmove(e.pageX, e.pageY); } function jseyesmousemoveIE() { jseyesmove(event.clientX+document.body.scrollLeft, event.clientY+document.body.scrollTop); } jseyes(); Работает в IE и Maxthon. Не работает в Mozilla, Opera, Chrome. Помогите с решением. Никак не могу понять почему!! Умоляю, заставьте его работать в вышеуказанных браузерах!!! :cray: :cray: :cray: :cray: |
Цитата:
<!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> <style type='text/css'> div { width: 300px; height: 300px; border: 1px solid } </style> <script type="text/javascript"> function Go(Event) { var o=Event || window.event document.getElementById('x').value=o.clientX document.getElementById('y').value=o.clientY } </script> </head> <body> <div onmousemove=Go(event)> <p>Двигай мышкой тут...</p> </div> <input type='text' id='x' /> <input type='text' id='y' /> </body> </html> |
Часовой пояс GMT +3, время: 14:47. |