Use JavaScript to realize the automatic rotation of elements

Use JavaScript to realize the automatic rotation of elements

JavaScript module

  <script>
        //声明一个函数
        function rotate() {
    
    
            //每隔100毫秒调用一次fun函数(调整旋转速度的地方)
            setInterval(fun, 100)
        }

        //声明一个number类型的变量
        var deg = 0;

        //声明一个函数
        function fun() {
    
    
            //指定id尾login的标签
            var obj = document.getElementById("login");
            //每次自增1度
            deg += 1;
            //长度加上单位deg
            var d = deg + "deg";
            //拼接控制旋转的方法
            obj.style.transform = "rotate(" + d + ")";
        }
    </script>

html module

<!--调用函数-->
<body onload="rotate();">
<div class="re">
    <!--id为login-->
    <div class="fa" id="login">
        <div class="faa">
            <form>
                <div>账户:<input type="text"></div>
                <div>密码:<input type="password"></div>
                <div><input type="submit"></div>
            </form>
        </div>
    </div>
</div>
</body>

Guess you like

Origin blog.csdn.net/qq_49249150/article/details/108060805