為什么執(zhí)行這段代碼中間會一閃呢?
var imgUrl = ['3.png','1.png','3.png','2.png','3.png','1.png','4.png','2.png'];
var ele = document.getElementById('animal');
animation(ele,imgUrl);
function animation(ele,imgUrl) {
? ?ele.style.backgroundRepeat = 'no-repeat';
? ?var index = 0;//標(biāo)注在數(shù)組中的位置
? ?function run() {
? ? ? ?ele.style.backgroundImage = 'url('+imgUrl[index]+')';
? ? ? ?index++;
? ? ? ?if (index >= imgUrl.length) {
? ? ? ? ? ?index = 0;
? ? ? ?}
? ? ? ?setTimeout(run,200);
? ?}
? ?run();
}