动画方案除了CSS还有什么
window.setTimeout()
window.setInterval():指定某个任务每隔一段时间就执行一次,也就是无限次的定时执行
<h3>用setTimeout实现计数器功能</h3>
<div id="result">0</div>
<button onclick="startCount()">开始计数</button>
<button onclick="stopCount()">停止计数</button>
<script>
var conter=0
var is_timer_on=false
var t;
function timedCount(){
//计数函数:找到id名为result的组件,赋值counter
document.getELementId('result').innerHTML=counter;
//counter递增
counter++;
//在指定的毫秒数后调用函数或这函数表达式
t=setTImeout(timedCount,1000)
}
function startCount(){
if (!is_timer_on){
is_tmer_on=true
timeCount()
}
}
function endCount(){
clearTimeout()
is_timer_on=false
}
</script>