精髓: 使用 requestAnimationFrame 达到流畅的效果
var div = document.querySelector('#drawing')
var speed = 0;
var rotateDeg = 0;
var accelete = 0.05;
var aId
function aFun(){
rotateDeg = (rotateDeg + speed) % 360;
div.style.transform = `rotate(${rotateDeg}deg)`
speed =speed < 50? (speed + accelete) :speed;
aId = window.requestAnimationFrame(aFun)
}
div.onmouseover = function(){
aId = requestAnimationFrame(aFun)
}
div.onmouseout = function(){
speed = 0;
rotateDeg = 0;
div.style.transform = `rotate(${rotateDeg}deg)`
window.cancelAnimationFrame(aId)
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。