文本滚动功能不会运行



这是我的代码:

<!doctype html>
<html>
<head>
<title>Algorithms</title>
<script type="text/javascript">
function move_paragraph() {
next = current + "px";
current + -1;
if (current > 300) {
current = 0;
}
paragraph.style.left = next;
var rate = 18;
setTimeout(move_paragraph, rate);
}
function init() {
paragraph = document.getElementById("original");
paragraph.style.position = "absolute";
current = 0;
move_paragraph();
}
</script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body class="Algbody" onload="init();">
<p id="original">This is a text scroll</p>
<br>
<br>
</body>
</html>

它应该是一个基本的文本滚动,但它不会在IE,Firefox或Chrome中运行。谁能看出错误?

在第 8 行你有 - 而不是 =。

current +- 1;更改为current += 1;

你可以在CSS而不是Javascript中执行此操作。

<!doctype html>
<html>
<head>
<title>Algorithms</title>
<link href="style.css" rel="stylesheet" type="text/css">
<style>
@keyframes text-scroll {
0% { left: 0; }
100% { left: 300px; }
}
#original {
position: absolute;
animation: text-scroll 3s forwards;
}
</style>
</head>
<body class="Algbody">
<p id="original">This is a text scroll</p>
<br>
<br>
</body>
</html>

最新更新