Movendo HTML com Botões












CÓDIGO HTML


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    input:hover {
        background-color: rgb(152, 231, 152);
    }
   

</style>


<body style="background-color: grey;">
   
   
    <div style = "width:680px; height:30 px;margin-top:25px;  text-align: center;">
        <input type="button" id="Acima"    value="Acima"     style ="width:70px; height:20 px; text-align:center;"><br/>
        <input type="button" id="Direita"  value="Direita"   style ="width:70px; height:20 px; text-align:center;" >
        <input type="button" id="Esquerda" value="Esquerda"  style ="width:70px; height:20 px; text-align:center;" ><br/>
        <input type="button" id="Abaixo"   value="Abaixo"    style ="width:70px; height:20 px; text-align:center;" >
    </div>
         <div id="tabuleiro" style = "background-color:white;margin-top:30px; margin-left: 50px; width: 610px ; height: 460px; border:4px solid black;">
        <div  id="elemento" style="border-radius: 50%;border:1px solid #ff0000a4;background-color: red; width:8px; height:8px;margin-top:2px;margin-left:2px;"></div></div>
   

</body>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">







$(function() {
    x=2;
    y=2;
    $("#Direita").click( function(){
       
        x=x-10;
        if (x<10){
            x=598;
        }
    $("#elemento").animate({

        marginLeft: x+"px",
        marginTop: y +"px"},10, function () {
       
    });
});

$("#Esquerda").click(function(){
        x=x+10;
        if (x>598){
            x=2;
        }
    $("#elemento").animate({

    marginLeft: x+"px",
    marginTop: y+"px"},10, function () {
       
    });  
});

$("#Acima").click(function(){
        y=y-10;
        if (y<2){
            y=449;
        }
    $("#elemento").animate({

    marginLeft: x+"px",
    marginTop: y+"px"},10, function () {
       
    });  
});

$("#Abaixo").click(function(){
        y=y+10;
        if (y>449){
            y=2;
        }
    $("#elemento").animate({

    marginLeft: x+"px",
    marginTop: y+"px"},10, function () {
       
    });  
});

});

</script>
</html>



Comentários

Postagens mais visitadas deste blog

CD4511 - Display 7 Segmentos

Joystick, Servos e Laser