squareDancing/js/custom.js

208 lines
5.7 KiB
JavaScript
Raw Normal View History

2021-11-18 10:29:59 +00:00
// 总条数
var num = 0;
var timer = null;
var actionTimer = null;
2021-11-19 07:30:08 +00:00
var moveTimer = null;
2021-11-23 13:54:58 +00:00
var dancerTimer = null;
// 经过几秒关闭一起喊
var allSayTimer = 5000;
2021-11-18 10:29:59 +00:00
// 动作
2021-11-19 15:57:11 +00:00
var actionArr = ['dancing-left','dancing-right','dancing-down','dancing-up','dancing-wobble','dancing-wobble-right'];
2021-11-19 07:30:08 +00:00
// 人物位移动画
var moveArr = ['run-right','run-left','run-right-top','run-left-top','run-right-bottom','run-left-bottom'];
// 随机荧光棒动画
var fluoArr = ['stick-go','stickcome'];
2021-11-18 10:29:59 +00:00
var peopleId = 0;
2021-11-19 13:54:50 +00:00
// 窗体宽度
var winWidth = $(window).width();
// 窗体高度
var winheight = $(window).height();
//控制速度1px
var speed = 1;
2021-11-19 15:57:11 +00:00
var startIndex = 0;
2021-11-25 01:27:35 +00:00
// 领舞关闭时间
var dancingTime = 6000;
// 6秒钟检测移动位置
var runTime = 6000;
// 随机移动的定时器
var upTimer = null;
// 荧光棒关闭时间
var fluoTime = 6000//默认6秒关闭
2021-11-23 08:45:28 +00:00
// 集体舞ji
2021-11-19 15:57:11 +00:00
function allDancing(dangcing){
if(dangcing!=''){
actionArr.forEach((item,index)=>{
var haveDan = $(`.people-img`).is(`.${item}`);
if(haveDan){
$(`.people-img`).removeClass(item);
// $(`.people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]);
$(`.people-img`).addClass(dangcing);
2021-11-23 13:14:51 +00:00
$(`.leading-dancer`).removeClass(item);
$(`.leading-dancer`).addClass(dangcing);
2021-11-19 15:57:11 +00:00
}
})
setTimeout(()=>{
startIndex = 0;
var allPeople = $('.dance-floor').find('.people-img').length;
2021-11-23 13:14:51 +00:00
$(`.people-img`).removeClass(dangcing);
2021-11-25 01:27:35 +00:00
var suiDanTimer = setInterval(()=>{
2021-11-19 15:57:11 +00:00
if(startIndex==allPeople){
clearInterval(suiDanTimer);
} else {
startIndex++;
$(`.data${startIndex} .people-img`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]);
}
2021-11-25 03:05:04 +00:00
},3000)
2021-11-23 13:14:51 +00:00
},10000)
2021-11-19 15:57:11 +00:00
}
2021-11-18 10:29:59 +00:00
}
// 创建人物时随机分配舞蹈
2021-11-18 11:11:00 +00:00
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)
2021-11-18 10:29:59 +00:00
}
2021-11-23 01:56:09 +00:00
// 个人动作舞
2021-11-23 06:10:39 +00:00
function peopleAction(id,aevent){
actionArr.forEach((item,index)=>{
2021-11-23 13:14:51 +00:00
var haveDan = $(`#${id} .people-img`).is(`.${item}`);
2021-11-23 06:10:39 +00:00
if(haveDan){
2021-11-23 13:14:51 +00:00
$(`#${id} .people-img`).removeClass(item);
$(`#${id} .people-img`).addClass(aevent);
} else {
$(`#${id} .people-img`).addClass(aevent);
2021-11-23 06:10:39 +00:00
}
})
2021-11-23 01:56:09 +00:00
}
// 位移事件
2021-11-23 01:56:09 +00:00
function upMove(id){
var odivu = document.getElementById(`${id}`);
2021-11-25 01:27:35 +00:00
upTimer = setInterval(()=>{
$(`#${id}`).animate({top:`${Math.floor(Math.random()*90)}%`,left:`${Math.floor(Math.random()*90)}%`},Math.floor(Math.random()*40000+10000));
2021-11-25 01:27:35 +00:00
},runTime)
2021-11-19 13:54:50 +00:00
}
2021-11-25 01:27:35 +00:00
// 随机位移
function moveEv(id){
upMove(id);
2021-11-19 07:30:08 +00:00
}
2021-11-18 10:29:59 +00:00
// 关闭说话
function closeSay(index){
$(`.data${index} .speak`).addClass("dn");
}
// 开启说话
function sayIng(index){
$(`.data${index} .speak`).removeClass("dn");
setTimeout(()=>{
closeSay(index);
2021-11-19 07:30:08 +00:00
},6000)
2021-11-18 10:29:59 +00:00
}
// 一起喊
function allSay(val){
$(`.dance-people .speak`).removeClass("dn");
$(`.dance-people .speak`).html(val);
setTimeout(()=>{
$(`.dance-people .speak`).addClass("dn");
},allSayTimer)
}
2021-11-19 15:57:11 +00:00
// 退出广场
function exitEv(id){
$(`${id}`).remove();
}
// 进入广场
2021-11-30 05:46:55 +00:00
function peopleObj(name,uid,say,action,active_time, is_admin){
2021-12-08 02:38:18 +00:00
// console.log(name + ' ' + uid + ' ' + say + ' ' + action + ' ' + active_time + ' ' + is_admin, 'sssss')
2021-11-18 10:29:59 +00:00
let yspHtml = '';
let yspData = [
{
2021-11-23 13:14:51 +00:00
id:'',
2021-11-23 01:56:09 +00:00
uid:uid,
2021-11-19 13:54:50 +00:00
top:`${Math.random()*500}px`,
left:`${Math.random()*1500}px`,
2021-11-18 10:29:59 +00:00
name:name,//用户名
say:say,//说话内容
peopleImg:`people-img0${Math.floor(Math.random()*6+1)}`,//人物图片
ying_guang:`stick-0${Math.floor(Math.random()*5+1)}`,//荧光棒
2021-11-19 07:30:08 +00:00
dancin:action,
2021-11-30 05:46:55 +00:00
active_time: active_time,
is_admin: is_admin
2021-11-18 10:29:59 +00:00
}
]
$.each(yspData, function (commentIndex, comment) {
2021-11-30 05:46:55 +00:00
let bigStick = comment.is_admin == 1 ? 'stick-swing-big-tow' : ''
2021-11-18 10:29:59 +00:00
yspHtml += `
2021-11-25 10:11:01 +00:00
<div id="${comment.uid}" data-time="${comment.active_time}" class="dance-people data${peopleId}" style="top: ${comment.top}; left: ${comment.left};">
2021-11-19 15:57:11 +00:00
<div class="speak ">${comment.say}</div>
2021-11-18 10:29:59 +00:00
<div class="people-img ${comment.peopleImg} ${comment.dancin}">
2021-11-30 05:46:55 +00:00
<div class="stick stick-swing ${bigStick} ${comment.ying_guang}"></div>
2021-11-18 10:29:59 +00:00
<div class="people-name ">${comment.name}</div>
</div>
</div>`
2021-11-29 11:16:23 +00:00
});//如果是舰长需要加上stick-swing-big-tow
2021-11-18 10:29:59 +00:00
$('.dance-floor').prepend(yspHtml);
2021-11-23 01:56:09 +00:00
moveEv(uid);
2021-11-23 13:14:51 +00:00
// 随机舞
randomDancing(peopleId);
// 开始说话
sayIng(peopleId);
2021-11-23 13:14:51 +00:00
peopleId++
2021-11-19 15:57:11 +00:00
// 执行退出事件
// exitEv(`#peopleId${peopleId-1}`)
2021-11-18 10:29:59 +00:00
}
2021-11-23 13:54:58 +00:00
// 领舞者个人说话的动作
2021-11-23 13:14:51 +00:00
function dancerOwn(dancing){
actionArr.forEach((item,index)=>{
var haveDan = $(`.leading-dancer`).is(`.${item}`);
if(haveDan){
$(`.leading-dancer`).removeClass(item);
$(`.leading-dancer`).addClass(dancing);
}
})
2021-11-23 13:54:58 +00:00
setTimeout(()=>{
dancerRandom();
},6000)
2021-11-23 13:14:51 +00:00
}
2021-11-23 13:54:58 +00:00
// 领舞者随机的动作
function dancerRandom(){
2021-11-19 15:57:11 +00:00
// 领舞者随机动效
2021-11-23 13:54:58 +00:00
dancerTimer = setInterval(()=>{
2021-11-19 15:57:11 +00:00
actionArr.forEach((item,index)=>{
var haveDan = $(`.leading-dancer`).is(`.${item}`);
if(haveDan){
$(`.leading-dancer`).removeClass(item);
$(`.leading-dancer`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]);
2021-11-23 14:04:00 +00:00
} else {
$(`.leading-dancer`).addClass(actionArr[Math.floor(Math.random()*actionArr.length)]);
2021-11-19 15:57:11 +00:00
}
})
2021-11-25 01:27:35 +00:00
},dancingTime)
2021-11-23 13:54:58 +00:00
}
$(function(){
dancerRandom();
2021-11-23 08:21:20 +00:00
// 自动切歌
2021-11-23 09:53:26 +00:00
changeMusic();
2021-11-23 08:45:28 +00:00
var audio=document.getElementById('music');
if(audio){
2021-11-23 09:53:26 +00:00
audio.loop = false;
audio.addEventListener('ended', function () {
changeMusic()
}, false);
2021-11-23 08:45:28 +00:00
}
2021-11-25 10:11:01 +00:00
// 60s检测一次 十分钟没发言的删除
setInterval(function () {
delExpireDiv()
}, 60000)
2021-11-30 05:46:55 +00:00
2021-11-23 10:04:02 +00:00
//烟花
// setInterval(()=>{
// setTimeout(function() {
// $('.w3-agilefireworks').fireworks();
// });
// },6000)
2021-11-19 15:57:11 +00:00
2021-11-19 07:30:08 +00:00
})