css3 实现: div{ animation: myfirst 5s; } @keyframes myfirst{ 0% {left:0px; top:0px;} 100% {left:100px; top:20px;} } jquery实现: $("#box").animate({left:"100px",top:"20px"}); 那就自己实现吧: function animate(sX,sY,eX,eY,time,call){ this.currentX = sX,this.currentY = sY; this.speedX = (eX - sX)/(time*100),this.speedY = (eY - sY)/(time*100); this.start = function(){ let vm =this; setTimeout(function(){ if(vm.currentX < eX){ vm.currentX += vm.speedX; vm.currentY += vm.speedY; call(vm.currentX,vm.currentY); vm.start(); } },10) } } var callBack = function(x,y){ console.log('x =>',x,'y =>',y) } var animate1 = new animate(0,0,200,100,5,callBack) animate1.start() 部分结果如下:上面的只是实现过程,需要你自己加上dom操作
css3 实现:
div{
}
@keyframes myfirst
{
}
jquery实现:
$("#box").animate({left:"100px",top:"20px"});
那就自己实现吧: