Created
March 9, 2023 21:17
-
-
Save perseoq/69fd7c87253005c111e962a044ed9382 to your computer and use it in GitHub Desktop.
Cambia de tamaño una linea con Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> | |
<title>Document</title> | |
</head> | |
<body> | |
<canvas id="myCanvas"></canvas> | |
<input type="number" id="lineLength" min="0" max="50000" value="1"> | |
<script> | |
const canvas = document.getElementById('myCanvas'); | |
const ctx = canvas.getContext('2d'); | |
function drawLine(length) { | |
ctx.beginPath(); | |
ctx.moveTo(0, 0); | |
ctx.lineTo(length, 0); | |
ctx.stroke(); | |
} | |
const lineLengthInput = document.getElementById('lineLength'); | |
lineLengthInput.addEventListener('input', () => { | |
const length = lineLengthInput.value; | |
drawLine(length); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment