I have the following HTML code, which creates a div called “paddle” inside a div called “board”. I’m preparing a small game of Pong and the “paddle” div represents the paddle that will receive the ball.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pong Game</title>
<link rel="stylesheet" href="estilo.css">
<script src="script.js"></script>
</head>
<body>
<div id="board">
<div id="paddle"></div>
</div>
</body>
</html>
#board {
margin: 0 auto;
background-color: black;
border-top: 5px solid skyblue;
border-bottom: 5px solid skyblue;
width: 500px;
height: 500px;
position: relative;
}
#paddle {
background-color: skyblue;
width: 10px;
height: 50px;
position: absolute;
top: 250px;
left: 480px;
cursor: pointer;
}
I need you to help me with a JavaScript code that Drags and Drops the “paddle” div within the limits of the “board” div and only vertically