// 总条数 var num = 0; var timer = null; var actionTimer = null; // 粉丝的昵称 var nameArr = ['鹅鹅鹅鹅鹅鹅','打嗝','旋风腿儿','霹雳腿儿','老寒腿儿','哇咔咔蹦跶']; // 粉丝说的话 var sayArr = ['没人','内容','空空风','美女姐姐','小阔爱','老阔爱']; // 动作 var actionArr = ['dancing-left','dancing-right','dancing-down','dancing-UP','dancing-Wobble','dancing-Wobble-right']; var peopleId = 0; // 集体舞 function allDancing(){ actionArr.forEach((item,index)=>{ var chooseIdex = Math.floor(Math.random()*num); var haveDan = $(`.people-img`).is(`.${item}`); if(haveDan){ $(`.people-img`).removeClass(item); $(`.people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]); } }) setTimeout(()=>{ console.log('关闭集体舞'); clearInterval(actionTimer); },3000) } // 随机舞 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)]); // } // }) // } 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) } // 关闭说话 function closeSay(index){ $(`.data${index} .speak`).addClass("dn"); } // 开启说话 function sayIng(index){ $(`.data${index} .speak`).removeClass("dn"); setTimeout(()=>{ closeSay(index); },3000) } function peopleObj(name,say,action){ // 开始说话 sayIng(peopleId); randomDancing(peopleId); let yspHtml = ''; let yspData = [ { id:peopleId++, top:`${Math.random()*80+1}%`, left:`${Math.random()*90+1}%`, name:name,//用户名 say:say,//说话内容 peopleImg:`people-img0${Math.floor(Math.random()*6+1)}`,//人物图片 ying_guang:`stick-0${Math.floor(Math.random()*5+1)}`,//荧光棒 dancin:action } ] $.each(yspData, function (commentIndex, comment) { yspHtml += `
${comment.say}${comment.id}
${comment.name}
` }); $('.dance-floor').prepend(yspHtml); setTimeout(()=>{ closeSay(num); },3000); } $(function(){ // setTimeout(()=>{ // console.log('开始集体舞'); // allDancing(); // },50000) 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==200){ clearInterval(timer); } else { peopleObj(nameArr[nameIndex],sayArr[sayIndex],actionArr[actionIndex]); } },0) })