使用旋转字符串添加文本框和动画

时间:2014-11-23 13:26:42

标签: javascript

大家好,我们的老师要求我们添加输入类型=“文本”并使用带有这些代码的旋转字符串为其设置动画:

 <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>

但我不知道怎么做。请帮忙谢谢。:)

2 个答案:

答案 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;);来自剧本。