# Typed.js , testo automatico in stile terminale MacOS e macchina da scrivere

<!-- Source: https://alessioangeloro.it/typed-js-testo-automatico-stile-terminale-macos-macchina-scrivere/ -->
<!-- Last modified: 2017-04-24T11:53:51+02:00 -->

Ho trovato una libreria Javascript fichissima! Permette di creare un testo con scrittura automatica in stile macchina da scrivere, quello con il cursore tipo prompt dei comand Dos o Terminale dei sistemi Linux e Unix, altrimenti detto testo type writing.

[](https://alessioangeloro.it/wp-content/uploads/2017/04/typed.js.gif)

Vediamo subito un esempio

Ed ecco il codice

Per prima cosa incorporiamo la libreria **typed.js** in questo modo

&lt;script src="js/typed.js" type="text/javascript"&gt;&lt;/script&gt;
poi lo script

&lt;script&gt;
    document.addEventListener('DOMContentLoaded', function(){

        Typed.new("#typed", {
            stringsElement: document.getElementById('typed-strings'),
            typeSpeed: 30,
            backDelay: 500,
            loop: true,
            contentType: 'html', // or text
            // defaults to null for infinite loop
            loopCount: null,
            //cursorChar: "_",
            //fadeOut: true,
            callback: function(){ foo(); },
            resetCallback: function() { newTyped(); }
        });

        var resetElement = document.querySelector('.reset');
        if(resetElement) {
            resetElement.addEventListener('click', function() {
                document.getElementById('typed')._typed.reset();
            });
        }

    });

    function newTyped(){ /* A new typed object */ }

    function foo(){ console.log("Callback"); }

    &lt;/script&gt;
il CSS

&lt;link href="normal.css" rel="stylesheet"/&gt;    
&lt;style&gt;
        body{margin-top:-110px !important;}
        /* code for animated blinking cursor */
        .typed-cursor{
            opacity: 1;
            font-weight: 100;
            -webkit-animation: blink 0.7s infinite;
            -moz-animation: blink 0.7s infinite;
            -ms-animation: blink 0.7s infinite;
            -o-animation: blink 0.7s infinite;
            animation: blink 0.7s infinite;
        }
        @-keyframes blink{
            0% { opacity:1; }
            50% { opacity:0; }
            100% { opacity:1; }
        }
        @-webkit-keyframes blink{
            0% { opacity:1; }
            50% { opacity:0; }
            100% { opacity:1; }
        }
        @-moz-keyframes blink{
            0% { opacity:1; }
            50% { opacity:0; }
            100% { opacity:1; }
        }
        @-ms-keyframes blink{
            0% { opacity:1; }
            50% { opacity:0; }
            100% { opacity:1; }
        }
        @-o-keyframes blink{
            0% { opacity:1; }
            50% { opacity:0; }
            100% { opacity:1; }
        }

        .typed-fade-out{
            opacity: 0;
            animation: 0;
            transition: opacity .25s;
        }
&lt;/style&gt;
ed infine l&#8217;HTML

    &lt;div class="wrap"&gt;
        &lt;div class="type-wrap"&gt;
            &lt;div id="typed-strings"&gt;
                &lt;span&gt;Ciao! Mi chiamo&lt;strong&gt; Alessio Angeloro&lt;/strong&gt; e sono un...&lt;/span&gt;
                &lt;p&gt;Web Developer WordPress &amp; Joomla&lt;/p&gt;
                &lt;p&gt;PHP/MySQL, jQuery, HTML, CSS3, Bootstrap, UIKit, ...&lt;/p&gt;
                &lt;p&gt;&lt;a href="#"&gt;Contattami!&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;span id="typed" style="white-space:pre;"&gt;&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
Con un pò di fantasia possiamo creare anche un finestra in stile terminal

[](https://alessioangeloro.it/wp-content/uploads/2017/04/testo_effetto_terminale.png)

Questo è il CSS

@import url(http://fonts.googleapis.com/css?family=Ubuntu:400,500);
* {
  padding: 0;
  margin: 0; }

body {
  font-family: "Ubuntu", sans-serif;
  font-size: 100%;
  background: #f8f8f8; }

a {
  text-decoration: none;
  color: #666; }
  a:hover {
    color: #999; }

p {
  line-height: 2em;
  margin: 0 0 20px; }

.wrap {
  max-width: 700px;
  margin: auto; }

.header {
  width: 100%;
  min-height: 450px;
  margin: 0 auto 30px;
  padding: 10px 0;
  background-size: 100%; }
  @media screen and (max-width: 1500px) {
    .header {
      background-size: auto; } }
  .header .h1 {
    margin: 10px 0 20px;
    font-size: 2.5em;
    text-align: center;
    color: #fff;
    text-shadow: #000 0px 2px 4px; }

.head-wrap {
  margin: 30px auto 30px;
  -webkit-transition: all 0.5s ease-out;
  -moz-transition: all 0.5s ease-out;
  -ms-transition: all 0.5s ease-out;
  -o-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out;
  text-align: center; }

.tagline {
  display: block;
  padding: 20px 0 0;
  opacity: 0;
  color: #fff;
  font-weight: 600;
  text-shadow: #000 0px 1px 3px;
  -webkit-transition: all 0.5s ease-out;
  -moz-transition: all 0.5s ease-out;
  -ms-transition: all 0.5s ease-out;
  -o-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out; }

.shift-text {
  margin: 80px auto 110px; }
  .shift-text .text-body {
    height: 120px; }
  .shift-text .tagline {
    opacity: 0.9; }

/* text editor styles */
.text-editor-wrap {
  display: block;
  margin: auto;
  max-width: 530px;
  border-radius: 10px;
  box-shadow: rgba(0, 0, 0, 0.8) 0px 20px 70px;
  clear: both;
  overflow: hidden;
  -webkit-transition: all 0.5s ease-out;
  -moz-transition: all 0.5s ease-out;
  -ms-transition: all 0.5s ease-out;
  -o-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out; }

.title-bar {
  padding: 5px 0;
  font-family: "Lucida Grande", sans-serif;
  font-size: 0.75em;
  text-align: center;
  text-shadow: rgba(255, 255, 255, 0.8) 0px 1px 0px;
  background-color: #f8f8f8;
  background-image: -webkit-linear-gradient(top, #e8e8e8, #bcbbbc);
  background-image: -moz-linear-gradient(top, #e8e8e8, #bcbbbc);
  background-image: linear-gradient(top, #e8e8e8, #bcbbbc);
  box-shadow: inset rgba(255, 255, 255, 0.7) 0px 1px 1px;
  border-bottom: #6a6a6a 1px solid; }

.text-body {
  height: 250px;
  background-color: rgba(0, 0, 0, 0.85);
  padding: 10px;
  color: #f0f0f0;
  text-shadow: #000 0px 1px 0px;
  font-family: "Consolas", "Courier New", "Courier";
  font-size: 1.75em;
  line-height: 1.40em;
  font-weight: 500;
  text-align: left;
  overflow: hidden;
  -webkit-transition: all 0.5s ease-out;
  -moz-transition: all 0.5s ease-out;
  -ms-transition: all 0.5s ease-out;
  -o-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out; }

.h2 {
  margin: 10px 0; }

.note {
  text-align: center; }

.inline-code {
  padding: 2px 5px;
  background: #fff;
  border: #CCC 1px solid;
  border-radius: 4px; }

hr {
  margin: 20px 0;
  border: 0;
  border-bottom: #fff 1px solid;
  border-top: #f0f0f0 1px solid; }

pre {
  margin: 0 auto 20px;
  padding: 20px;
  color: #444;
  font-family: "Consolas", "Courier New", "Courier";
  font-weight: 500;
  background: #fff;
  border: #EEE 1px solid;
  border-radius: 10px;
  overflow: auto; }

.typed-cursor {
  opacity: 1;
  font-weight: 100;
  -webkit-animation: blink 0.7s infinite;
  -moz-animation: blink 0.7s infinite;
  -ms-animation: blink 0.7s infinite;
  -o-animation: blink 0.7s infinite;
  animation: blink 0.7s infinite; }

@-keyframes blink {
  0% {
    opacity: 1; }

  50% {
    opacity: 0; }

  100% {
    opacity: 1; } }
@-webkit-keyframes blink {
  0% {
    opacity: 1; }

  50% {
    opacity: 0; }

  100% {
    opacity: 1; } }
@-moz-keyframes blink {
  0% {
    opacity: 1; }

  50% {
    opacity: 0; }

  100% {
    opacity: 1; } }
@-ms-keyframes blink {
  0% {
    opacity: 1; }

  50% {
    opacity: 0; }

  100% {
    opacity: 1; } }
@-o-keyframes blink {
  0% {
    opacity: 1; }

  50% {
    opacity: 0; }

  100% {
    opacity: 1; } }
.btn-wrap {
  display: block;
  margin: 0 auto 1em;
  clear: both;
  text-align: center; }

.btn {
  display: inline-block;
  position: relative;
  margin: 0 10px 5px;
  text-align: left;
  vertical-align: top; }
  @media screen and (max-width: 500px) {
    .btn {
      display: block; } }
  .btn &gt; a {
    display: block;
    position: relative;
    padding: 0.8em 1.75em 0.7em;
    color: #fff;
    text-shadow: rgba(0, 0, 0, 0.3) 0px -1px 0px;
    font-size: 1.5em;
    font-weight: 400;
    line-height: 1em;
    text-align: center;
    background-color: #3479b4;
    border-radius: 4px;
    z-index: 0;
    -webkit-transition: all 0.1s ease-in-out;
    -moz-transition: all 0.1s ease-in-out;
    -ms-transition: all 0.1s ease-in-out;
    -o-transition: all 0.1s ease-in-out;
    transition: all 0.1s ease-in-out; }
    .btn &gt; a:hover {
      background-color: #4f92cc; }
  .btn p {
    line-height: 1em; }
    .btn p a {
      color: #333; }
      .btn p a:hover {
        color: #CCC; }

## Come personalizzare lo script typed.js

Typed.new(".element", {
    strings: ["First sentence.", "Second sentence."],
    // Optionally use an HTML element to grab strings from (must wrap each string in a &lt;p&gt;)
    stringsElement: null,
    // typing speed
    typeSpeed: 0,
    // time before typing starts
    startDelay: 0,
    // backspacing speed
    backSpeed: 0,
    // shuffle the strings
    shuffle: false,
    // time before backspacing
    backDelay: 500,
    // Fade out instead of backspace (must use CSS class)
    fadeOut: false,
    fadeOutClass: 'typed-fade-out',
    fadeOutSpeed: 500, // milliseconds
    // loop
    loop: false,
    // null = infinite
    loopCount: null,
    // show cursor
    showCursor: true,
    // character for cursor
    cursorChar: "|",
    // attribute to type (null == text)
    attr: null,
    // either html or text
    contentType: 'html',
    // call when done callback function
    callback: function() {},
    // starting callback function before each string
    preStringTyped: function() {},
    //callback for every typed string
    onStringTyped: function() {},
    // callback for reset
    resetCallback: function() {}
});
&nbsp;
