<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 100px;
height: 100px;
background-color: black;
}
</style>
</head>
<body>
<div></div>
<script>
// 获取div标签
var box = document.querySelector('div')
// 默认旋转角度为0
var angle = 0
function updata(){
angle += 5
box.style.transform = `rotate(${angle}deg)`
aniCode = requestAnimationFrame(updata)
}
updata()
// 定时器,5秒之后停止动画(清除动画)
setTimeout(function(){
cancelAnimationFrame(aniCode)
},5000)
</script>
</body>
</html>
js动画旋转
最新推荐文章于 2024-07-10 17:54:45 发布