伙计们,我想把我的打字文本改为两行。
这是 Demo
Plz检查此代码
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 SCRIPT
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);
}());
答案 0 :(得分:9)
您可以向.writer
添加white-space: pre-line;
声明,以便打破这些行,如下所示:
.writer {
font:bold 23px arial;
white-space: pre-line;
}
<强> WORKING DEMO 强>
<强> 16.6 White space: the 'white-space' property 强>
pre-line
此值指示用户代理折叠空白序列。行 在保留的换行符中被破坏,并且必要时填写 线盒。
值得注意的是pre-line
价值is supported in IE8+。