Esta sencilla rutina como su nombre lo indica nos permite mover una imagen, en este caso cuando nos posicionamos encima con el mouse empieza a moverse.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<html> <head><script> function detenerError(){ return true } window.onerror=detenerError </script> <style> .shakeimage{ position:relative } </style> <script language="JavaScript1.2"> var rector=3 var stopit=0 var a=1 function init(which){ stopit=0 shake=which shake.style.left=0 shake.style.top=0 } function rattleimage(){ if ((!document.all&&!document.getElementById)||stopit==1) return if (a==1){ shake.style.top=parseInt(shake.style.top)+rector } else if (a==2){ shake.style.left=parseInt(shake.style.left)+rector } else if (a==3){ shake.style.top=parseInt(shake.style.top)-rector } else{ shake.style.left=parseInt(shake.style.left)-rector } if (a<4) a++ else a=1 setTimeout("rattleimage()",50) } function stoprattle(which){ stopit=1 which.style.left=0 which.style.top=0 } </script> <title>JavaScript Mover imagen</title> </head> <body> <p align="left"><font face="Arial" color="#000000"><small>Ejemplo: </small></font><img src="ejemplos/red.gif" class="shakeimage" onMouseover="init(this);rattleimage()" onMouseout="stoprattle(this)" onclick="alert('Aquí no ha pasado nada')"></p> </body> </html> |