Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 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.onmouseup = 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. if(botonSelect != null)
  32. {
  33. var x = event.clientX;
  34. var y = event.clientY;
  35.  
  36. botonSelect.style.top = y+"px";
  37. botonSelect.style.left = x+"px";
  38.  
  39. }
  40.  
  41. }
  42.  
  43. function reinicio(event){
  44.  
  45. if(this.value == "a"){
  46. botonSelect = document.getElementById("buttonA");
  47. this.style.top = 0+"px";
  48. this.style.left = 0+"px";
  49. botonSelect = null;
  50. }
  51. if(this.value == "b"){
  52. botonSelect = document.getElementById("buttonB");
  53. this.style.top = 0+"px";
  54. this.style.left = 0+"px";
  55. botonSelect = null;
  56. }
  57. if(this.value == "c"){
  58. botonSelect = document.getElementById("buttonC");
  59. this.style.top = 0+"px";
  60. this.style.left = 0+"px";
  61. botonSelect = null;
  62. }
  63.  
  64.  
  65. }
  66.  
  67. }
  68. </script>
  69. <style>
  70. input{
  71. position:relative;
  72. }
  73. </style>
  74. <body>
  75. <input type="button" id ="buttonA" value = "a"/> <!-- 65-->
  76. <input type="button" id ="buttonB" value = "b"/> <!-- 66-->
  77. <input type="button" id ="buttonC" value = "c"/> <!-- 67-->
  78.  
  79. </body>
  80.  
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement