Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head></head>
- <script>
- window.onload = function(){
- var botonSelect = null;
- document.onkeyup = seleccionar;
- document.onmouseup = mover;
- buttonA.onclick = reinicio;
- buttonB.onclick = reinicio;
- buttonC.onclick = reinicio;
- function seleccionar(event){
- if(event.keyCode == 65){ // Boton A pulsado
- botonSelect = document.getElementById("buttonA");
- }
- else if(event.keyCode == 66){ // Boton B pulsado
- botonSelect = document.getElementById("buttonB");
- }
- else if(event.keyCode == 67){ // Boton C pulsado
- botonSelect = document.getElementById("buttonC");
- }
- else {
- botonSelect = null;
- }
- }
- function mover(event){
- if(botonSelect != null)
- {
- var x = event.clientX;
- var y = event.clientY;
- botonSelect.style.top = y+"px";
- botonSelect.style.left = x+"px";
- }
- }
- function reinicio(event){
- if(this.value == "a"){
- botonSelect = document.getElementById("buttonA");
- this.style.top = 0+"px";
- this.style.left = 0+"px";
- botonSelect = null;
- }
- if(this.value == "b"){
- botonSelect = document.getElementById("buttonB");
- this.style.top = 0+"px";
- this.style.left = 0+"px";
- botonSelect = null;
- }
- if(this.value == "c"){
- botonSelect = document.getElementById("buttonC");
- this.style.top = 0+"px";
- this.style.left = 0+"px";
- botonSelect = null;
- }
- }
- }
- </script>
- <style>
- input{
- position:relative;
- }
- </style>
- <body>
- <input type="button" id ="buttonA" value = "a"/> <!-- 65-->
- <input type="button" id ="buttonB" value = "b"/> <!-- 66-->
- <input type="button" id ="buttonC" value = "c"/> <!-- 67-->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement