Skip to content

Commit

Permalink
finally got it working
Browse files Browse the repository at this point in the history
  • Loading branch information
avdol0521 committed Oct 28, 2023
0 parents commit 9ebcad6
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>Movement :D</title>
</head>
<body>
<div class="casing">
<div class="LR">
<button class="left">L</button>
<button class="right">R</button>
</div>
<div class="screen">
<div class="box"></div>
</div>
<div class="UD">
<button class="up">U</button>
<button class="down">D</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Get elements n stuff
const box = document.querySelector(".box");
const upB = document.querySelector(".up");
const downB = document.querySelector(".down");
const leftB = document.querySelector(".left");
const rightB = document.querySelector(".right");
let newT = 0;
let newL = 0;

// functions
const moveU = () => {
newT -= 10;
box.style.top = newT + "px";
console.log(newT);
};

const moveD = () => {
newT += 10;
box.style.top = newT + "px";
console.log(newT);
};

const moveL = () => {
newL -= 10;
box.style.left = newL + "px";
console.log(newL);
};

const moveR = () => {
newL += 10;
box.style.left = newL + "px";
console.log(newL);
};

//Event listeners
upB.onclick = moveU;
downB.onclick = moveD;
leftB.onclick = moveL;
rightB.onclick = moveR;
54 changes: 54 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
body {
/* background-image: url(bg.jpg); */
background-color: #717171;
display: flex;
justify-content: center;
align-items: center;
min-height: 90vh;
}
.casing {
background-color: #ff6a6a;
position: relative;
height: 400px;
width: 900px;
border-radius: 50px;
display: flex;
justify-content: space-around;
align-items: center;
}
.LR, .UD {
background-color: #e04040;
height: 100px;
width: 150px;
border-radius: 20px;
display: flex;
justify-content: space-evenly;
align-items: center;
}
button {
border: none;
background-color: #772727;
height: 60px;
width: 60px;
border-radius: 20px;
}
.screen {
position: relative;
background-color: #c3c3c3;
height: 300px;
width: 500px;
border-radius: 20px;
display: flex;
justify-content: center;
align-items: center;
}
.box {
height: 100px;
width: 100px;
position: relative;
top: 0;
left: 0;
background-color: #404040;
border-radius: 20px;
transition: top 0.2s ease-in-out, left 0.2s ease-in-out;
}

0 comments on commit 9ebcad6

Please sign in to comment.