Typed.js是我发现的一个很神奇的小工具。整个js插件虽然仅仅只有400行,但是这个插件的效果让人眼睛一亮。而且这个插件似乎支持bower,所以个个bower使用者也可以尽情使用。
我们一步一步来使用这个插件:
1 2 3 4 5 6 7 8 9 10 11 12 | <script src="jquery.js"></script><script src="typed.js"></script><script> $(function(){ $(".element").typed({ strings: ["First sentence.", "Second sentence."], typeSpeed: 0 }); });</script>...<span class="element"></span> |
如果你想让你的输入光标闪起来:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | .typed-cursor{ opacity: 1; -webkit-animation: blink 0.7s infinite; -moz-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; }} |
如果你想使用html作为文本,那么:
1 | $(".typed").typed({ strings: ["Sentence with <br>line break."] }); |
如果你想使用纯text作为文本,那么:
1 2 3 | <span id="typed" style="white-space:pre"></span>...$(".typed").typed({ strings: ["Sentence with a\nline break."] }); |
如果你想在文本中停顿:
1 2 3 4 5 6 7 8 | <script> $(function(){ $(".element").typed({ // Waits 1000ms after typing "First" strings: ["First ^1000 sentence.", "Second sentence."] }); });</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 32 33 34 35 | <script> $(function(){ $(".element").typed({ strings: ["First sentence.", "Second sentence."], // typing speed typeSpeed: 0, // time before typing starts startDelay: 0, // backspacing speed backSpeed: 0, // time before backspacing backDelay: 500, // loop loop: false, // false = infinite loopCount: false, // 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() {} }); });</script> |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com