diff --git a/js/custom.js b/js/custom.js index 6b4ecdb..f3fe023 100644 --- a/js/custom.js +++ b/js/custom.js @@ -25,19 +25,28 @@ function allDancing(){ },3000) } // 随机舞 -function randomDancing(){ +function randomDancing(id){ actionTimer = setInterval(()=>{ - var len = $('.dance-people').length; - for (var i = 0; i < num; i++) { - actionArr.forEach((item,index)=>{ - // var chooseIdex = Math.floor(Math.random()*num); - var haveDan = $(`.data${i} .people-img`).is(`.${item}`); - if(haveDan){ - $(`.data${i} .people-img`).removeClass(item); - $(`.data${i} .people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]); - } - }) - } + // var len = $('.dance-people').length; + // for (var i = 0; i < num; i++) { + // actionArr.forEach((item,index)=>{ + // // var chooseIdex = Math.floor(Math.random()*num); + // var haveDan = $(`.data${i} .people-img`).is(`.${item}`); + // if(haveDan){ + // $(`.data${i} .people-img`).removeClass(item); + // $(`.data${i} .people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]); + // } + // }) + // } + actionArr.forEach((item,index)=>{ + // var chooseIdex = Math.floor(Math.random()*num); + var haveDan = $(`.data${id} .people-img`).is(`.${item}`); + if(haveDan){ + $(`.data${id} .people-img`).removeClass(item); + $(`.data${id} .people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]); + } + }) + console.log(id); },3000) } // 关闭说话 @@ -54,6 +63,7 @@ function sayIng(index){ function peopleObj(name,say,action){ // 开始说话 sayIng(peopleId); + randomDancing(peopleId); let yspHtml = ''; let yspData = [ { @@ -87,20 +97,16 @@ $(function(){ // console.log('开始集体舞'); // allDancing(); // },50000) - setTimeout(()=>{ - console.log('开启随机舞') - randomDancing(); - },4000)//需要2s的倍数 timer = setInterval(()=>{ var nameIndex = Math.floor(Math.random()*nameArr.length); var sayIndex = Math.floor(Math.random()*sayArr.length); var actionIndex = Math.floor(Math.random()*actionArr.length); num++; - if(num==300){ + if(num==10){ clearInterval(timer); } else { peopleObj(nameArr[nameIndex],sayArr[sayIndex],actionArr[actionIndex]); } - },1000) + },000) })