JSFiddle - React, Tailwind, and code Playground
HTML
<div class="code-example">
<div class="num-line">
6<br>7<br>8<br>9<br>10<br>12<br>13<br>14<br>15
</div>
<div class="code-block">
<span class="static-code"><body><br></span>
<span class="static-code" style="white-space:pre"> <h1>My First Website</h1><br></span>
<span class="code-animate bold" style="white-space:pre"></span>
<span class="static-code"></body><br></html></span>
</div>
<div class="clearfix"></div>
</div>
<script>
$(function(){
$(".code-animate").typed({
strings: [" <p>Lorem ipsum dolor sit amet, ei sit atomorum forensibus, pro ad denique vituperata. His ni.</p>"],
typeSpeed: 1,
backSpeed: 50,
contentType: 'text',
loop: false
});
});
</script>
CSS
.code-example {
font-size: 12px;
width: 400px;
border: 1px solid black;
}
.num-line {
float: left;
background-color: #e6e6e6;
padding: 3px 5px;
margin-right: 5px;
text-align: right;
display: inline-block;
}
.code-block {
display: inline-block;
padding-top: 3px;
width: 30em;
}
.code-animate: {
display: inline;
word-wrap: break-word;
overflow-wrap: break-word;
word-break: break-all;
}
.static-code {
display: block;
}
.clearfix {
clear: both;
}
JavaScript
// The MIT License (MIT)
// Typed.js | Copyright (c) 2014 Matt Boldt | www.mattboldt.com
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
! function($) {
"use strict";
var Typed = function(el, options) {
// chosen element to manipulate text
this.el = $(el);
// options
this.options = $.extend({}, $.fn.typed.defaults, options);
// attribute to type into
this.isInput = this.el.is('input');
this.attr = this.options.attr;
// show cursor
this.showCursor = this.isInput ? false : this.options.showCursor;
// text content of element
this.elContent = this.attr ? this.el.attr(this.attr) : this.el.text()
// html or plain text
this.contentType = this.options.contentType;
// typing speed
this.typeSpeed = this.options.typeSpeed;
// add a delay before typing starts
this.startDelay = this.options.startDelay;
//...