老師講的非常好,很贊,不用canvas,用div的背景圖,改變背景圖的background-position,應(yīng)該也能實現(xiàn)吧
2021-01-30
有bug,點show后點reset不會歸位
將theAnimation定義為全局變量,具體代碼:(三處改動)
1、在函數(shù)外部定義 var theAnimation;
2、function initCanvas(){
clearInterval(theAnimation); //在initCanvas添加一行代碼
3、function show(){
clearInterval(theAnimation); //添加一行代碼,清除定時器
theAnimation = setInterval(function(){ // 把前面的var去掉
將theAnimation定義為全局變量,具體代碼:(三處改動)
1、在函數(shù)外部定義 var theAnimation;
2、function initCanvas(){
clearInterval(theAnimation); //在initCanvas添加一行代碼
3、function show(){
clearInterval(theAnimation); //添加一行代碼,清除定時器
theAnimation = setInterval(function(){ // 把前面的var去掉
有bug,點show后點reset出錯
將theAnimation定義為全局變量,具體代碼:(三處改動)
1、在函數(shù)外部定義 var theAnimation;
2、function initCanvas(){
clearInterval(theAnimation); //在initCanvas添加一行代碼
3、function show(){
clearInterval(theAnimation); //添加一行代碼,清除定時器
theAnimation = setInterval(function(){ // 把前面的var去掉
將theAnimation定義為全局變量,具體代碼:(三處改動)
1、在函數(shù)外部定義 var theAnimation;
2、function initCanvas(){
clearInterval(theAnimation); //在initCanvas添加一行代碼
3、function show(){
clearInterval(theAnimation); //添加一行代碼,清除定時器
theAnimation = setInterval(function(){ // 把前面的var去掉
2個bug一個是點完show不能立即點RESET,您加一個變量就可以解決了,還有一個是不能瘋狂點show負責會開很多setInterval,您只需單擊show的時候清除一下就可以了