From c5fcb3d64edf80504ff6eccb40845e6e67a9b71e Mon Sep 17 00:00:00 2001 From: cp <463911765@qq.com> Date: Mon, 6 Dec 2021 15:10:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/custom.js | 69 +++++++++++++++++++++------- js/handle.js | 125 +++++++++++++++++++-------------------------------- 2 files changed, 101 insertions(+), 93 deletions(-) diff --git a/js/custom.js b/js/custom.js index 0ef3d19..042b1b0 100644 --- a/js/custom.js +++ b/js/custom.js @@ -10,8 +10,6 @@ var allSayTimer = 5000; var actionArr = ['dancing-left','dancing-right','dancing-down','dancing-up','dancing-wobble','dancing-wobble-right']; // 人物位移动画 var moveArr = ['run-right','run-left','run-right-top','run-left-top','run-right-bottom','run-left-bottom']; -// 随机荧光棒动画 -var fluoArr = ['stick-go','stickcome']; var peopleId = 0; // 窗体宽度 var winWidth = $(window).width(); @@ -26,8 +24,6 @@ var dancingTime = 6000; var runTime = 6000; // 随机移动的定时器 var upTimer = null; -// 荧光棒关闭时间 -var fluoTime = 6000//默认6秒关闭 // 集体舞ji function allDancing(dangcing){ if(dangcing!=''){ @@ -56,16 +52,17 @@ function allDancing(dangcing){ },10000) } } -// 创建人物时随机分配舞蹈 +// 随机舞 function randomDancing(id){ - $(`.data${id} .people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]); -} -// 荧光棒动画事件 -function fluoEv(id,fluoEvent){ - $(`#${id} .stick`).addClass(fluoEvent); - setTimeout(()=>{ - $(`#${id} .stick`).removeClass(fluoEvent); - },fluoTime) + actionArr.forEach((item,index)=>{ + 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)]); + } else { + $(`.data${id} .people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]); + } + }) } // 个人动作舞 function peopleAction(id,aevent){ @@ -79,13 +76,55 @@ function peopleAction(id,aevent){ } }) } -// 位移事件 +// 上 function upMove(id){ var odivu = document.getElementById(`${id}`); upTimer = setInterval(()=>{ - $(`#${id}`).animate({top:`${Math.floor(Math.random()*90)}%`,left:`${Math.floor(Math.random()*90)}%`},Math.floor(Math.random()*40000+10000)); + // if(parseInt(odivu.style.top) <=10){ + // // clearInterval(upTimer); + // // downMove(id); + // $(`#${id}`).animate({top:`${Math.floor(Math.random()*90)}%`,left:`${Math.floor(Math.random()*90)}%`},Math.floor(Math.random()*40000+10000)); + // } else { + $(`#${id}`).animate({top:`${Math.floor(Math.random()*90)}%`,left:`${Math.floor(Math.random()*90)}%`},Math.floor(Math.random()*40000+10000)); + // } },runTime) } +// // 下 +// function downMove(id){ +// var odivd = document.getElementById(`${id}`); +// var downTimer = setInterval(()=>{ +// if(parseInt(odivd.style.top) >=86){ +// clearInterval(downTimer); +// upMove(id); +// } else { +// $(`#${id}`).animate({top:`${Math.floor(Math.random()*90)}%`,left:`${Math.floor(Math.random()*90)}%`},Math.floor(Math.random()*40000+10000)); +// } +// },10) +// } +// // 左 +// function leftMove(id){ +// var odivl = document.getElementById(`${id}`); +// var leftTimer = setInterval(()=>{ +// if(odivl.offsetLeft < 10){ +// clearInterval(leftTimer); +// rightMove(id); +// } else { +// $(`#${id}`).animate({top:`${Math.floor(Math.random()*90)}%`,left:`${Math.floor(Math.random()*90)}%`},Math.floor(Math.random()*40000+10000)); +// } +// },10) +// } +// // 右 +// function rightMove(id){ +// var odivr = document.getElementById(`${id}`); +// var rightTimer = setInterval(()=>{ +// if(odivr.offsetLeft >= 86){ +// clearInterval(rightTimer); +// leftMove(id); +// } else { +// $(`#${id}`).animate({top:`${Math.floor(Math.random()*90)}%`,left:`${Math.floor(Math.random()*90)}%`},Math.floor(Math.random()*40000+10000)); +// } +// },10) +// } // 随机位移 function moveEv(id){ upMove(id); diff --git a/js/handle.js b/js/handle.js index 43689f6..697858e 100644 --- a/js/handle.js +++ b/js/handle.js @@ -16,21 +16,19 @@ let leaderTime = 15*60 // 何时添加镜头 var addJingTime = 2000;//2秒 // 事件列表-中文 -let eventTextList = ['切歌', '跳', '向左', '向右', '左抖腿', '右抖腿', '抖动', '一起喊', '镜头','击剑','起飞'] -// 个人---荧光棒列表-中文 -let fluoTextList = ['击剑','起飞']; -// 领舞---荧光棒列表-中文 -let leaderFluoList = ['一起击剑','一起起飞']; +let eventTextList = ['切歌', '跳', '向左', '向右', '左抖腿', '右抖腿', '抖动', '一起喊', '镜头'] // 领舞者喊的集体舞 let allEventList = ['切歌', '一起跳', '一起向左', '一起向右', '一起左抖腿', '一起右抖腿', '一起抖动', '一起喊', '镜头'] // 镜头列表 let list = ['scale-left', 'scale-right', 'scale-bottom-left', 'scale-bottom-right'] // 烟花次数 let firTimes = 0; -// 个人喊舞:根据事件文字 获取事件名 +// 根据事件文字 获取事件名 function getEvent(name) { let map = { '烟花':'fireworks', + '一起击剑':'stickcome', + '起飞':'stickgo', '切歌' : 'change_song', '跳' : 'dancing-down', '向左' : 'dancing-left', @@ -45,10 +43,12 @@ function getEvent(name) { return map[name] ? map[name] : '' } -// 领舞者:根据事件文字 获取事件名 +// 根据事件文字 获取领舞者事件名 function getLeaderEvent(name) { let map = { '烟花':'fireworks', + '一起击剑':'stickcome', + '起飞':'stickgo', '切歌' : 'change_song', '一起跳' : 'dancing-down', '一起向左' : 'dancing-left', @@ -62,29 +62,22 @@ function getLeaderEvent(name) { return map[name] ? map[name] : '' } -// -function getLeaderFluoEvent(name) { - let leadMap = { - '一起击剑':'stickcome', - '一起起飞':'stick-go' - } - return leadMap[name] ? leadMap[name] : '' -} + // 随机选择镜头 function scale() { return list[Math.floor(Math.random() * 3)]; } // 字符串包含的事件 (仅取第一个) -// function getFirstEventKeyword(name) { -// let event = '' -// $.each(eventTextList, function (index, item) { -// if (name.toString().indexOf(item) != -1) { -// event = item -// return false -// } -// }) -// return event -// } +function getFirstEventKeyword(name) { + let event = '' + $.each(eventTextList, function (index, item) { + if (name.toString().indexOf(item) != -1) { + event = item + return false + } + }) + return event +} function music() { $.get(musicUrl, function (res) { @@ -111,18 +104,6 @@ function changeMusic() { function peopleHan(val){ return eventTextList.includes(val); } -// 领舞者:根据事件文字 获取事件名 -function getFluoEvent(name) { - let fluoMap = { - '击剑':'stickcome', - '起飞':'stick-go' - } - return fluoMap[name] ? fluoMap[name] : '' -} -// 个人喊荧光棒 -function peopleFluo(val){ - return fluoTextList.includes(val); -} // 领舞喊舞 function dancer(val){ return allEventList.includes(val); @@ -175,12 +156,12 @@ function receiveMessage(event) // 领舞信息 目前为领舞名称 let leaderInfo = '' + // 高能榜第一位设为领舞 - if (highList!=undefined && highList.length > 0) { + if (highList.length > 0) { leaderInfo = highList[0] } - leaderInfo = '内有猛犬小心' - // leaderInfo = '饺子吃肉肉' + // leaderInfo = '内有猛犬小心' // uid是否存在 不存在则存入uidObj let isNew = 0 @@ -217,6 +198,7 @@ function receiveMessage(event) leader.text = dm.text leader.event = eventName ? eventName : leaderEvent } + // 新用户 if(dm.is_new==1){ // if(dm.uname!=leader.uname){//如果弹幕的人的名字不等于领舞者的名字,就创建一个人物 @@ -232,17 +214,13 @@ function receiveMessage(event) // 舰长添加大宝剑 $(`#${dm.uid} .stick`).addClass("stick-swing-big-tow"); } - setTimeout(()=>{//关闭当前说话 + setTimeout(()=>{ $(`#${dm.uid} .speak`).addClass("dn"); },3000) - // 舞者喊舞---动作舞 + // 舞者喊舞 if(peopleHan(dm.text)){ peopleAction(`${dm.uid}`,dm.event); } - // 舞者喊舞---荧光棒 - if(peopleFluo(dm.text)){ - fluoEv(`${dm.uid}`,getFluoEvent(dm.text)); - } } num++; @@ -293,29 +271,29 @@ function receiveMessage(event) } } //领舞起飞 - // if(leader.text==="起飞"){ - // if(firTimes==0){ - // firTimes++; - // $('.stick').removeClass('stick-swing'); - // $('.stick').addClass('stick-go'); - // setTimeout(()=>{ - // $('.stick').removeClass('stick-go'); - // $('.stick').addClass('stick-swing'); - // firTimes = 0; - // },6000) - // } - // } + if(leader.text==="起飞"){ + if(firTimes==0){ + firTimes++; + $('.stick').removeClass('stick-swing'); + $('.stick').addClass('stick-go'); + setTimeout(()=>{ + $('.stick').removeClass('stick-go'); + $('.stick').addClass('stick-swing'); + firTimes = 0; + },6000) + } + } //一起击剑 - // if(leader.text==="一起击剑"){ - // if(firTimes==0){ - // firTimes++; - // $('.stick').addClass('stickcome'); - // setTimeout(()=>{ - // $('.stick').removeClass('stickcome'); - // firTimes = 0; - // },6000) - // } - // } + if(leader.text==="一起击剑"){ + if(firTimes==0){ + firTimes++; + $('.stick').addClass('stickcome'); + setTimeout(()=>{ + $('.stick').removeClass('stickcome'); + firTimes = 0; + },6000) + } + } // 领舞喊一起喊 if (leader.text.length >= 4) { @@ -323,6 +301,7 @@ function receiveMessage(event) allSay(leader.text.slice(4)); } } + // 领舞自己喊跳舞 if(peopleHan(dm.text)){ clearInterval(dancerTimer); @@ -332,16 +311,6 @@ function receiveMessage(event) if(dancer(leader.text)){ allDancing(leader.event); } - // 领舞喊荧光棒事件 - if(getLeaderFluoEvent(leader.text)!=''){ - if(firTimes==0){//防多次说话 - firTimes++; - console.log(getLeaderFluoEvent(leader.text)); - setTimeout(()=>{ - firTimes = 0; - },5000) - } - } } // -------------------- 每条弹幕处理 end ----------------------- }