javaScript实现元素匀速运动 元素缓速运动(先快后慢)

    xiaoxiao2026-10-02  7

    1、实现元素匀速运动 

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> #cicle { width: 20px; height: 20px; border-radius: 50%; background-color: #8c0000; position: absolute; top: 50px; } </style> </head> <body> <button id="btn" οnclick="move()">匀速运动</button> <div id="cicle"></div> </body> <script> function move() { var cicle = document.getElementById("cicle"); var num=0; var target=400; var timer= setInterval(function(){ if(num<=400){ num+=5;//元素匀速运动 <pre name="code" class="html"> num=num+(target-num)/100;//元素缓速运动(先快后慢) cicle.style.left=num+"px"; }else { clearInterval(timer); } },10); }</script></html>

    转载请注明原文地址: https://ju.6miu.com/read-1312553.html
    最新回复(0)