Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize typewriter effect with pure js

Shulou Source: shulou.com Published: 2022-06-02 22:24:57 10月03日 Update

This article is about how pure js can achieve typewriter effect. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Effect picture

Application scenario

It's not very useful. I just saw that there was a similar effect on the Internet. I wrote 40 or 50 lines of code that I couldn't understand, so I tried to realize it simply.

Html

Css h3 {width: 800px; line-height: 40px; border-bottom: 1px solid; margin: 200px auto; font-size: 24px;} .animate {display: inline-block; padding: 05px; vertical-align: 3px; font-size: 20px; font-weight: normal;} .animate.on {animation: fade 1.5s infinite forwards;} @ keyframes fade {from {opacity: 0;} to {opacity: 1 }}

Js

Let textBox = $('# text-box'); let index = 0 index str = 'Welcome to my websitekeeper; let len = str.length; function input () {textBox.html (str.substr (0, index) +' |'); setTimeout (function () {index++; if (index = len + 1) {$('.animate'). AddClass ('on'); return;} input () }, Math.random () * 600) console.log (index);} input (); Thank you for reading! This is the end of this article on "how to achieve typewriter effect with pure js". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Effect typewriter typing content more article good practical not big code just scene effect picture article usefulness look knowledge ten lines reference try Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB NVidia Linux Shulou Technology