JS实现小球移动(点击移动,点击停止)

时间:2025-03-31 20:24:18

这么简单的东西,一堆收费的,还特么有很多都是直接cv别人免费的拿来收费,这么缺?

<style>
    div{
        width: 100px;
        height: 100px;
        border: 1px solid black;
        border-radius: 50%;
        text-align: center;
        line-height: 70px;
        cursor: pointer;
        
    }
</style>
<body>
    <div  onclick="moo()" click="" style="position: absolute;">
       <p >点我移动</p> 
    </div>
</body>
<script>
    //接收
    var borName = ("mo");
    //定义初始div位置
    qiuX=0;
    var i = 0;
    var count = 0;
    function moo(){
        count++;
        if(count % 2 != 0){
             ="停止移动";
            i = setInterval(function(){
                qiuX+=1;
                //修改div的left top
                =qiuX+"px";
                
            }, 10);
        }else{
            clearInterval(i);
             = "点我移动";
        }
        
    }
        

</script>