添加文本框并使用旋转字符串进行动画处理

Add text box and animate using rotating string

本文关键字:字符串 动画 处理 旋转 文本 添加      更新时间:2023-09-26

嗨,我们的老师要求我们添加输入类型="文本",并使用带有以下代码的旋转字符串对其进行动画处理:

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

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

试试这个:

s = "hello world" ;
l = strlen(s) ;
tmp = substr(s, 1, l-2) + substr(s, 0, 1) ;
s = tmp

你只需要从脚本调用animate_string('这里的元素 id');