大家好,我们的老师要求我们添加输入类型=“文本”并使用带有这些代码的旋转字符串为其设置动画:
<html>
<head>
<title>Javascript Basic Animation</title>
<script type="text/javascript">
function animate_string(id)
{
var element = document.getElementById(id);
var textNode = element.childNodes[0]; // assuming no other children
var text = textNode.data;
setInterval (function ()
{
text = text[text.length - 1] + text.substring (0, text.length - 1);
textNode.data = text;
}, 100);
}
</script>
</head>
<body onload="animate_string('target')">
<pre>
Write a Javascript program to rotate the string 'HELLO WORLD'
in right direction by periodically removing one letter from
the end of the string and attaching it to the front.
</pre>
<font size="21">
<pre id="target">HELLO WORLD</pre>
</font>
</body>
</html>
但我不知道怎么做。请帮忙谢谢。:)
答案 0 :(得分:1)
试试这个:
s = "hello world" ;
l = strlen(s) ;
tmp = substr(s, 1, l-2) + substr(s, 0, 1) ;
s = tmp
答案 1 :(得分:0)
你只需要调用animate_string(&#39; id of element here&#39;);来自剧本。