Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

creat and move square using js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script>
        
    x=700;
    y=400;
document.addEventListener("keypress",e=>{
    console.log(e.key)
var player = document.getElementById("player");
switch (e.key) {
    case "z" :
        y-=5;
        break;
    case "s" :
        y+=5;
        break;
    case "q" :
        x-=5;
        break;
    case "d" :
        x+=5;
        break;
    default:
        break;
}

    var pxl_x = String(x)+"px";
    var pxl_y = String(y)+"px";
    player.style.marginTop=pxl_y;
    player.style.marginLeft=pxl_x;
})
    </script>
    <title>move square</title>
    <style>
        h1{
            position: fixed;
            margin-left: 13%;
            font-family: cursive;
            color:rgb(26, 35, 36) ;
            font-size: 72px;

        }
        h2{
            position: fixed;
            margin-top: 140px;
            margin-left: 13%;
            font-family: cursive;
            color:rgb(46, 78, 82) ;
            font-size: 40px;
        }
        body{
            background-color: gray;
        }
        #player{
            background-color: black;
            border: red solid 3px;
            width: 100px;
            height: 100px;
            position: fixed;
            margin-top: 400px;
            margin-left: 700px;
            border-radius: 5px;
        }
        span{
            color: red;
        }
    </style>
</head>
<body>
    <h1>creat and move square using js !</h1>
    <h2>without get 2d method, use lowercases <span>Z</span>,<span>S</span>,<span>Q</span>,<span>D</span> to move the square.</h2>
    <div id="player">

    </div>
    
</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: stimulus params 
Javascript :: hardhat async test 
Javascript :: add a string regex in angular input 
Javascript :: for loop with if statement 
Javascript :: json returning object object 
Javascript :: get value from serialized json apex 
Javascript :: scrape data from ao3 
Javascript :: how to map array in react 
Javascript :: geojson featurecollection 
Javascript :: react js class component 
Javascript :: getx navigation 
Javascript :: identity-obj-proxy not working 
Javascript :: how to categorize a data in an array of object in javascript 
Javascript :: callback hell 
Javascript :: nested arrays javascript 
Javascript :: duplicate images in webpage js 
Javascript :: onselect in zebra datepicker 
Javascript :: string date to date in javascript 
Javascript :: how to pass a component as a prop in react 
Javascript :: vue back image 
Javascript :: ckeditor 5 on blur 
Javascript :: remove elemtns from an array with splice 
Javascript :: chinese icon in react native vector icons 
Javascript :: package.json merger 
Javascript :: what is the use of useparams in react 
Javascript :: random between min and max 
Javascript :: calcular sobra de divisão de parcelas js 
Javascript :: orderbychild firebase react 
Javascript :: how to make html with jquery 
Javascript :: collision javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =