You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
;(function(){letel=document.getElementById('move')letdone=false;letleft=0;lettop=0;letdirection='right'// left right down upletrequestId=nullfunctionstep(timestamp){switch(direction){case'right':
left+=10if(left===200){direction='down'}breakcase'down':
top+=10if(top===200){direction='left'}break;case'left':
left-=10if(left===0){direction='up'}break;case'up':
top-=10if(top===0){direction='right'}break;}el.style.left=`${left}px`el.style.top=`${top}px`if(!done){requestId=window.requestAnimationFrame(step);}}document.getElementById('start').onclick=()=>{done=falsewindow.cancelAnimationFrame(requestId)requestId=window.requestAnimationFrame(step)}document.getElementById('stop').onclick=()=>{done=true}})()
Activity
NicholasBaiYa commentedon Jul 21, 2019
使用画布实现。
haoolii commentedon Jul 22, 2019
GSAP
geraldchen890806 commentedon Jul 22, 2019
requestAnimationFrame
Drowned-fish commentedon Jul 24, 2019
requestAnimationFrame,浏览器专门为js动画提供的API。
xiaoqiangz commentedon Jun 24, 2022
setTimeout和 requestAnimationFrame都可以
panpanxuebing commentedon Dec 17, 2024