伙计们,我想在两行中输入文字。
这是我的 Demo
请检查此代码
HTML
<div id="container">
<div class="writer">Hi! This is a test text.
<br><br>
Can any one
Help me in this ?.</div>
</div>
JAVA脚本
var txt = $('.writer').text();
var timeOut;
var txtLen = txt.length;
var char = 0;
$('.writer').text('|');
(function typeIt() {
var humanize = Math.round(Math.random() * (200 - 30)) + 30;
timeOut = setTimeout(function() {
char++;
var type = txt.substring(0, char);
$('.writer').text(type + '|');
typeIt();
if (char == txtLen) {
$('.writer').text($('.writer').text().slice(0, -1)); // remove the '|'
clearTimeout(timeOut);
}
}, humanize);
}());
最佳答案
您可以将 white-space: pre-line;
声明添加到.writer
中,以断开各行,如下所示:
.writer {
font:bold 23px arial;
white-space: pre-line;
}
WORKING DEMO
值得注意的是
pre-line
的值为is supported in IE8+。关于javascript - 在Jquery中输入文字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22554589/