From 883c6cfb10a0704fdcccb3671d64216e87138bf6 Mon Sep 17 00:00:00 2001 From: chen <2659004835@qq.com> Date: Thu, 18 Nov 2021 19:11:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=B8=AA=E5=AF=B9=E5=BA=94=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/custom.js | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) 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) })