Skip to content

Commit d19feaf

Browse files
committedJan 18, 2021
add auto text effect
1 parent b6ef101 commit d19feaf

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed
 

‎30-auto text effect/index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="style.css" />
7+
<title>Auto Text Effect</title>
8+
</head>
9+
<body>
10+
<h1 id="text">Starting...</h1>
11+
<div>
12+
<label for="speed">Speed:</label>
13+
<input
14+
type="number"
15+
name="speed"
16+
id="speed"
17+
value="2"
18+
min="1"
19+
max="5"
20+
step="1"
21+
/>
22+
</div>
23+
<script src="script.js"></script>
24+
</body>
25+
</html>

‎30-auto text effect/script.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const textElement = document.getElementById("text");
2+
const speedElement = document.getElementById("speed");
3+
const text = "We Love Programming!";
4+
let index = 1;
5+
let speed = 300 / speedElement.value;
6+
7+
const writeText = () => {
8+
textElement.innerText = text.slice(0, index);
9+
index++;
10+
if (index > text.length) index = 1;
11+
setTimeout(writeText, speed);
12+
};
13+
14+
writeText();
15+
16+
speedElement.addEventListener("input", (e) => (speed = 300 / e.target.value));

‎30-auto text effect/style.css

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap");
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background-color: darksalmon;
9+
font-family: "Roboto", sans-serif;
10+
display: flex;
11+
flex-direction: column;
12+
align-items: center;
13+
justify-content: center;
14+
height: 100vh;
15+
overflow: hidden;
16+
margin: 0;
17+
}
18+
19+
div {
20+
position: absolute;
21+
bottom: 20px;
22+
background: rgba(0, 0, 0, 0.1);
23+
padding: 10px 20px;
24+
font-size: 18px;
25+
}
26+
27+
input {
28+
width: 50px;
29+
padding: 5px;
30+
font-size: 18px;
31+
background-color: darksalmon;
32+
border: none;
33+
text-align: center;
34+
}
35+
36+
input:focus {
37+
outline: none;
38+
}

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
| 27 | [Toast Notification](https://github.com/solygambas/html-css-fifty-projects/tree/master/27-toast%20notification) | [Live Demo](https://codepen.io/solygambas/pen/YzGBNgW) |
3636
| 28 | [GitHub Profiles](https://github.com/solygambas/html-css-fifty-projects/tree/master/28-github%20profiles) | [Live Demo](https://codepen.io/solygambas/pen/GRjzmVR) |
3737
| 29 | [Double Click Heart](https://github.com/solygambas/html-css-fifty-projects/tree/master/29-double%20click%20heart) | [Live Demo](https://codepen.io/solygambas/pen/XWjOaOK) |
38-
| 30 | [Auto Text Effect](https://github.com/solygambas/html-css-fifty-projects/tree/master/auto-text-effect) | [Live Demo](/auto-text-effect/) |
38+
| 30 | [Auto Text Effect](https://github.com/solygambas/html-css-fifty-projects/tree/master/30-auto%20text%20effect) | [Live Demo](https://codepen.io/solygambas/pen/JjRxrbM) |
3939
| 31 | [Password Generator](https://github.com/solygambas/html-css-fifty-projects/tree/master/password-generator) | [Live Demo](/password-generator/) |
4040
| 32 | [Good Cheap Fast](https://github.com/solygambas/html-css-fifty-projects/tree/master/good-cheap-fast) | [Live Demo](/good-cheap-fast/) |
4141
| 33 | [Notes App](https://github.com/solygambas/html-css-fifty-projects/tree/master/notes-app) | [Live Demo](/notes-app/) |

0 commit comments

Comments
 (0)
Please sign in to comment.