updated code

pull/229/head
mayank-0103 6 months ago
parent 84434979cb
commit 64c2616a80

@ -1,19 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Auto Text Effect</title>
</head>
<body>
<h1 id="text">Starting...</h1>
<div>
<label for="speed">Speed:</label>
<input type="number" name="speed" id="speed" value="1" min="1" max="10" step="1">
</div>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Auto Text Effect</title>
</head>
<body>
<h1 id="text">Starting...</h1>
<div>
<label for="speed">Speed:</label>
<input type="number" name="speed" id="speed" value="5" min="1" max="10" step="1">
</div>
<script src="script.js"></script>
</body>
<script src="script.js"></script>
</body>
</html>

@ -1,22 +1,21 @@
const textEl = document.getElementById('text')
const speedEl = document.getElementById('speed')
const text = 'We Love Programming!'
let idx = 1
let speed = 300 / speedEl.value
const textEl = document.getElementById('text');
const speedEl = document.getElementById('speed');
const text = 'xAI is an AI company with the mission of advancing scientific discovery and gaining a deeper understanding of our universe.';
let idx = 1;
let speed = 300 / speedEl.value;
writeText()
writeText();
function writeText() {
textEl.innerText = text.slice(0, idx)
textEl.innerText = text.slice(0, idx);
idx++
idx++;
if(idx > text.length) {
idx = 1
idx = 1;
}
setTimeout(writeText, speed)
setTimeout(writeText, speed);
}
speedEl.addEventListener('input', (e) => speed = 300 / e.target.value)
speedEl.addEventListener('input', (e) => speed = 300 / e.target.value);

@ -5,7 +5,7 @@
}
body {
background-color: darksalmon;
background-color: rgb(234, 255, 217);
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
@ -13,13 +13,19 @@ body {
justify-content: center;
height: 100vh;
overflow: hidden;
margin: 0;
width: 80vw;
margin: auto;
}
#text {
text-align: center;
}
div {
position: absolute;
bottom: 20px;
background: rgba(0, 0, 0, 0.1);
background: rgba(9, 105, 31, 0.1);
padding: 10px 20px;
font-size: 18px;
}
@ -28,7 +34,7 @@ input {
width: 50px;
padding: 5px;
font-size: 18px;
background-color: darksalmon;
background-color: rgb(172, 234, 201);
border: none;
text-align: center;
}

Loading…
Cancel
Save