Skip to content

Commit

Permalink
typewriter
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshayN committed May 15, 2022
1 parent 22dda1e commit 3f01983
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
22 changes: 15 additions & 7 deletions 151 - Type Writer Effect/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
margin: auto;
height: 100vh;
}
.container p {
font-size: 26px;
text-align: center;
padding: 18px;
font-weight: bold;
background-color: red;
}

button {
width: 270px;
height: 50px;
background-color: black;
color: white;
font-size: 20px;
cursor: pointer;
}
.typeLine{
display: flex;
flex-direction: column;
align-items: center;
}
.container span{
margin: 10px;
font-size: larger;
}
.container input{
height: 40px;
padding-left: 10px;
}
#mydiv {
width: 100%;
Expand Down
11 changes: 8 additions & 3 deletions 151 - Type Writer Effect/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@

<body>
<div class="container">
<p id="mytext"> Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem, asperiores.
</p>
<div class="typeLine">
<span>Enter the Text :</span>
<input type="text" id="inputText">
</div>
<div id="mydiv"></div>
<button id="mybutton">Type Writer Effect</button>
<button id="mybutton" onclick="typewrite()">Type Writer Effect</button>
</div>
<script src="js/index.js"></script>
</body>

</html>



24 changes: 12 additions & 12 deletions 151 - Type Writer Effect/js/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var mytext = document.getElementById("mytext");

var mydiv = document.getElementById("mydiv");
var mybutton = document.getElementById("mybutton");
var i = 0;
mybutton.onclick = function () {
var typewriter = setInterval(function () {
mydiv.textContent += mytext.textContent[i];
i++;
if (i > mytext.textContent.length - 1) {
mytext.textContent="Done !!!!!";
i=0;
clearInterval(typewriter);

const typewrite = () =>{
var text = document.getElementById("inputText").value;
mydiv.textContent="";
for(let i=0 ; i<text.length ; i++){
const j = i;
setTimeout(()=>{
mydiv.textContent += text[j];
}, 100*j)
}
}, 100);
};

}

0 comments on commit 3f01983

Please sign in to comment.