Skip to content

Instantly share code, notes, and snippets.

@EnterTheVoid-x86
Created January 9, 2022 23:23
Show Gist options
  • Save EnterTheVoid-x86/a55f77ccd2555fb60b34490eeb85cb0f to your computer and use it in GitHub Desktop.
Save EnterTheVoid-x86/a55f77ccd2555fb60b34490eeb85cb0f to your computer and use it in GitHub Desktop.
Typewriter animation with JavaSript
<body>
<p class="content">
<span class="typewrite anim-typewrite js-typewrite"></span>
</p>
</body>
var i = 0;
var txt = 'Typewriter animation style using JavaScript';
function typeWriter() {
if (i < txt.length) {
document.getElementsByClassName('js-typewrite')[0].innerHTML += txt.charAt(i);
i++;
setTimeout(typeWriter, 65);
}
}
setTimeout(typeWriter, 1000);
@import url(https://fonts.googleapis.com/css?family=Anonymous+Pro);
html {
min-height: 100%;
overflow: hidden;
}
body {
background-color: rgb(25,25,25);
color: rgba(255,255,255,.75);
font-family: 'Anonymous Pro', monospace;
height: calc(100vh - 8em);
padding: 4em;
}
.content {
display: block;
font-family: 'Anonymous Pro', sans-serif;
height: auto;
margin: auto;
position: relative;
text-align: center;
top: 40%;
width: -webkit-calc(70%);
}
.typewrite {
font-size: 180%;
border-right: 2px solid rgba(255,255,255,.75);
line-height: 1.15;
}
.anim-typewrite {
animation: blinkTextCursor 500ms infinite normal;
}
@keyframes blinkTextCursor{
from{border-right-color: rgba(255,255,255,.75);}
to{border-right-color: transparent;}
}
/* style inspired by Thiago Teles Pereira @thiagoteles */

Typewriter animation with JavaSript

Typewriter animation that is created with JavaScript. This animation can be used for content that spans across multiple lines without any modification unlike many CSS animations out there.

A Pen by Billy Ferris on CodePen.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment