Phiên bản đầy đủ: jsB@nk » Con trỏ » Kinh khí cầu bay theo chuột
URL: https://www.javascriptbank.com/dhtml-balloon-script-index.html
Một đoạn mã JavaScript khác để tạo hình ảnh bay theo con trỏ chuột trên trang web. Trong ví dụ là một quả kinh khí cầu.
Phiên bản đầy đủ: jsB@nk » Con trỏ » Kinh khí cầu bay theo chuột
URL: https://www.javascriptbank.com/dhtml-balloon-script-index.html
<script type="text/javascript">var Ver4=parseInt(navigator.appVersion.charAt(0))>=4var IE=navigator.appName.indexOf("Microsoft")!=-1var al, ex=-32, ey=-32, x0=-32, y0=-32 function BewegeAlien(){ // Neue Position des Alien berechnen if (Math.abs(ex-x0)>=10) { x0+=Math.floor((ex-x0)*0.1) } else if (ex!=x0) { x0+=Math.abs(ex-x0)/(ex-x0) } if (Math.abs(ey-y0)>=10) { y0+=Math.floor((ey-y0)*0.1) } else if (ey!=y0) { y0+=Math.abs(ey-y0)/(ey-y0) } // Neu Position setzen al.left=x0-82 al.top=y0 // Zeitverzâ€gerter Selbst-Aufruf setTimeout("BewegeAlien();",100)}function MeinMausEvent(e){ // Position des Maus-Cursors ermitteln if (Ver4) { if (!IE) { ex=e.pageX ey=e.pageY } else { ex=event.clientX+document.body.scrollLeft ey=event.clientY+document.body.scrollTop } }}function ScriptSetup(){ // Globale Variablen setzen und Maus-Event initialisieren if (Ver4) { if (!IE) { al=document.AlienLayer document.captureEvents(Event.MOUSEMOVE) } else { al=document.all.AlienLayer.style } document.onmousemove = MeinMausEvent BewegeAlien() }}function ZeigeAlien(){ // Setzen der Block-Level Container zur Anzeige der Grafiken if(Ver4) { s ='<DIV STYLE="visibility:hidden"></DIV>' s+='<DIV ID="AlienLayer" STYLE="position:absolute;' s+='top:-32; left:-32; width:32; height:32">' s+='<IMG NAME="alien" SRC="jc-ballo.gif" border=0></DIV>' document.writeln(s) }}window.onload = ScriptSetupZeigeAlien()</script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
http://javascriptbank.com/javascript/mouse/DHTML_balloon_script/jc-ballo.gif