<style>
div{
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 100px;
background-color: green;
}
</style>
</head>
<body>
<div></div>
<script>
function interval(callback, delay=100) {
let id = setInterval(()=>{callback(id)}, delay)
}
interval(animationId =>{
const div = document.querySelector('div')
let left = parseInt(window.getComputedStyle(div).left)
div.style.left = left + 10 + 'px'
if(left >= 200){
clearInterval(animationId)
interval((widthId)=>{
let width = parseInt(window.getComputedStyle(div).width)
div.style.width = width-10 +'px'
if(width <=50){
clearInterval(widthId)
}
})
}
})
console.log('hh');
</script>
异步任务 定时器
最新推荐文章于 2022-06-17 19:05:54 发布