【发布时间】:2016-09-30 22:29:04
【问题描述】:
我找到了一些我想测试的代码。我在这里想念什么? 我没有很多使用 JS 的经验,我不确定我是否遗漏了什么。如果有人能够提供帮助,我会非常高兴! 这是我的html:
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<link rel="stylesheet" type="text/css" href="spaced.css">
<link rel="shortcut icon" type="image/png" href="http://test.noa16.png"/>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300' rel='stylesheet' type='text/css'>
</head>
<body>
<p class="text" data-text="test text 010101101010101 lolol whatever"</p>
<script>
var printText = $('.text').data('text');
var contentArray = printText.split('/n');
$.each(contentArray, function(index, newLine) {
$('.text').append('<span style="display:block;" id="'+index+'"></span>');
var lineID = index;
var self = $(this);
setTimeout(function () {
$.each(self, function(index, chunk){
setTimeout(function () {
$('#'+lineID).append("<span>"+chunk+"</span>");
$('body, html').scrollTop($(document).height());
}, index*5);
});
}, index*100);
});
</script>
</body>
</html>
这是我的 CSS:
span {
min-width: 5px;
display: inline-block;
font-family: 'Source Sans Pro', sans-serif;
font-size: 0.85em;
letter-spacing: 1.5px;
color: #FFF;
}
body {
background: #111;
position: relative;
}
body, html {
height: 100%;
}
.text {
overflow: hidden;
height: auto;
}
有人知道为什么这对我不起作用吗?
【问题讨论】:
-
您的
p标签格式不正确。除此之外:您还没有告诉我们您希望这段代码做什么,或者您不希望它目前正在做什么? -
嘿!我希望它像这里显示的那样工作:codepen.io/hparton/pen/idDGK?editors=1011
-
好的,损坏的
p标签似乎就是它的全部。你还没有关闭它。"</p>应该是"></p>。 -
我只是在这里弄乱了 p 标签,正如您在链接中看到的那样,我删除了很多随机文本。但是现在在现场直播中,p 标签已关闭。但是当我加载页面时,它只显示黑屏。没有文字显示!
-
你是否包含了 jQuery 库?在上面的代码中看起来不像。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
标签: javascript html css