Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <html>
  2. <head></head>
  3. <script>
  4. window.onload = function(){
  5. var botonSelect = null;
  6.  
  7. document.onkeyup = seleccionar;
  8. document.onclick = mover;
  9. buttonA.onclick = reinicio;
  10. buttonB.onclick = reinicio;
  11. buttonC.onclick = reinicio;
  12.  
  13.  
  14. function seleccionar(event){
  15. if(event.keyCode == 65){ // Boton A pulsado
  16. botonSelect = document.getElementById("buttonA");
  17.  
  18. }
  19. else if(event.keyCode == 66){ // Boton B pulsado
  20. botonSelect = document.getElementById("buttonB");
  21. }
  22. else if(event.keyCode == 67){ // Boton C pulsado
  23. botonSelect = document.getElementById("buttonC");
  24. }
  25. else {
  26. botonSelect = null;
  27. }
  28. }
  29.  
  30. function mover(event){
  31.  
  32. if(botonSelect != null)
  33. {
  34. var x = event.clientX;
  35. var y = event.clientY;
  36.  
  37. botonSelect.style.top = y+"px";
  38. botonSelect.style.left = x+"px";
  39.  
  40. }
  41.  
  42. }
  43.  
  44. function reinicio(event){
  45.  
  46. if(this.value == "a"){
  47. this.style.top = 0+"px";
  48. this.style.left = 0+"px";
  49.  
  50.  
  51. }
  52. if(this.value == "b"){
  53. this.style.top = 0+"px";
  54. this.style.left = 0+"px";
  55. }
  56. if(this.value == "c"){
  57. this.style.top = 0+"px";
  58. this.style.left = 0+"px";
  59.  
  60. }
  61.  
  62.  
  63. }
  64.  
  65. }
  66. </script>
  67. <style>
  68. input{
  69. position:relative;
  70. }
  71. </style>
  72. <body>
  73. <input type="button" id ="buttonA" value = "a"/> <!-- 65-->
  74. <input type="button" id ="buttonB" value = "b"/> <!-- 66-->
  75. <input type="button" id ="buttonC" value = "c"/> <!-- 67-->
  76.  
  77. </body>
  78.  
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement