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.
Vediamo subito un esempio
Ed ecco il codice
Per prima cosa incorporiamo la libreria typed.js in questo modo
1 |
<script src="js/typed.js" type="text/javascript"></script> |
poi lo script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<script> 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"); } </script> |
il CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<link href="normal.css" rel="stylesheet"/> <style> 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; } </style> |
ed infine l’HTML
1 2 3 4 5 6 7 8 9 10 11 |
<div class="wrap"> <div class="type-wrap"> <div id="typed-strings"> <span>Ciao! Mi chiamo<strong> Alessio Angeloro</strong> e sono un...</span> <p>Web Developer WordPress & Joomla</p> <p>PHP/MySQL, jQuery, HTML, CSS3, Bootstrap, UIKit, ...</p> <p><a href="#">Contattami!</a></p> </div> <span id="typed" style="white-space:pre;"></span> </div> </div> |
Con un pò di fantasia possiamo creare anche un finestra in stile terminal
Questo è il CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
@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 > 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 > 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
Typed.new(".element", { strings: ["First sentence.", "Second sentence."], // Optionally use an HTML element to grab strings from (must wrap each string in a <p>) 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() {} }); |
Programmatore WordPress Esperto WooCommerce
Sono l’autore di questo blog con tanti trucchi e guide su WordPress e WooCommerce.
grazie mille