admin管理员组文章数量:1391975
How can I make text appear as if it is being typed one letter at a time with JavaScript and jQuery?
I tried hiding the content and then revealing one letter at a time with many setTimeout()
calls, but that seems highly inefficient.
Anyone know of a better way to do this or a script or plugin that can simulate this effect?
I also would like a blinking cursor!
How can I make text appear as if it is being typed one letter at a time with JavaScript and jQuery?
I tried hiding the content and then revealing one letter at a time with many setTimeout()
calls, but that seems highly inefficient.
Anyone know of a better way to do this or a script or plugin that can simulate this effect?
I also would like a blinking cursor!
Share Improve this question edited May 23, 2013 at 19:54 nalply 28.9k15 gold badges83 silver badges104 bronze badges asked May 23, 2013 at 19:07 Irfan MirIrfan Mir 2,1858 gold badges27 silver badges33 bronze badges 9- 3 What is inefficient about setTimeout()? – PinnyM Commented May 23, 2013 at 19:08
- 1 github./chadselph/jquery-typewriter – adaam Commented May 23, 2013 at 19:09
- You could progressively move an element that obscures the text to the right in increments. – user1726343 Commented May 23, 2013 at 19:09
- 1 Here's an nice, tiny plugin to do it: stackoverflow./a/10872412/2287470 – Joe Commented May 23, 2013 at 19:09
- @PinnyM That there are so many of them. one per each character. – Irfan Mir Commented May 23, 2013 at 19:11
2 Answers
Reset to default 4jQuery Typewriter available here: https://github./chadselph/jquery-typewriter
Here is an example of how it works:
$('.someselector').typewrite({
'delay': 100, //time in ms between each letter
'extra_char': '', //"cursor" character to append after each display
'trim': true, // Trim the string to type (Default: false, does not trim)
'callback': null // if exists, called after all effects have finished
});
here is an example I made
(function($){$.fn.typeWrite=function(s){
var o={content:$(this).text(),delay:50,t:this,i:0};
if(s){$.extend(o,s);}o.t.text('');
var i=setInterval(function() {
o.t.text(o.t.text()+o.content.charAt(o.i++));
if(o.i==o.content.length){clearInterval(i);}}
,o.delay);
return o.t;
};})(jQuery);
$('#test').typeWrite({content:'The stuff to type'});
<script src="https://ajax.googleapis./ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div id=test></div>
本文标签: javascriptMake text appear like it is being typed like with a typewriterStack Overflow
版权声明:本文标题:javascript - Make text appear like it is being typed like with a typewriter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744672346a2618899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论