690 lines
22 KiB
JavaScript
690 lines
22 KiB
JavaScript
|
||
let urlPrefix = getUrlPrefix()
|
||
let browser = checkVersion()
|
||
let env = EnvCheck();
|
||
if (env == 'test') {
|
||
new VConsole();
|
||
}
|
||
|
||
let lock = false //防止用户暴力点击加的锁
|
||
|
||
|
||
// 封装layer消息提醒框
|
||
let layerIndex
|
||
const showLoading = (content = '加载中...') => {
|
||
layer.open({
|
||
type: 2,
|
||
shadeClose: false,
|
||
content,
|
||
success (e) {
|
||
layerIndex = $(e).attr('index')
|
||
}
|
||
})
|
||
}
|
||
const hideLoading = (index) => {
|
||
layer.close(index)
|
||
}
|
||
const toastMsg = (content = '操作完成', time = 2) => {
|
||
layer.open({
|
||
content,
|
||
time,
|
||
skin: 'msg'
|
||
})
|
||
}
|
||
|
||
if (false) {//!browser.app
|
||
toastMsg('请在app内打开!');
|
||
} else {
|
||
$('.wrap').removeClass('no-in-app')
|
||
}
|
||
|
||
|
||
// 获取用户相关信息
|
||
let myFragment
|
||
const getUserInfo = (param) => {
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/act/luckySea/getUserActInfo',
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
$('.info-bottom').find('.avatar img').attr('src', res.data.avatar)
|
||
// if(res.data.nick.length > 10){
|
||
// res.data.nick = res.data.nick.slice(0,10) + '...'
|
||
// }
|
||
// $('.bottom').find('.nick').html(res.data.nick)
|
||
|
||
if (res.data.todayReward.toString().length >= 5) {
|
||
res.data.todayReward = (res.data.todayReward / 10000).toFixed(2) + 'w'
|
||
}
|
||
$('.info-bottom').find('.award').html(res.data.todayReward)
|
||
// if(res.data.pieceNum.toString().length >= 5) {
|
||
// res.data.diamonds = (res.data.diamonds/10000)
|
||
// }
|
||
$('.info-bottom').find('.fragment').html(res.data.pieceNum)
|
||
myFragment = res.data.pieceNum
|
||
} else {
|
||
return toastMsg(res.message)
|
||
}
|
||
},
|
||
error (err) {
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
// 获取用户碎片信息
|
||
const getUserPieceNum = () => {
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/act/luckySea/getUserActInfo',
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
$('.info-bottom').find('.fragment').html(res.data.pieceNum)
|
||
myFragment = res.data.pieceNum
|
||
} else {
|
||
return toastMsg(res.message)
|
||
}
|
||
lock = !lock
|
||
},
|
||
error (err) {
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
|
||
let userComeinTime //用户进入游戏界面时间,后端返回的timestamp
|
||
let startTime, drawStageStartTime, showResultStageStartTime, endTime //4个时间戳判断落于哪个界面
|
||
let timer2
|
||
let roundId
|
||
let roundIdArr = []
|
||
let arrTime = [], arrTime2 = [], arrTime3 = []
|
||
|
||
const getNewestAct = () => {
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/act/luckySea/getNewestAct',
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
if ($.isEmptyObject(res.data) || res.data.status === 4) {
|
||
return showLoading('服务器正在维护中...')
|
||
} else {
|
||
console.log(res.timestamp > res.data.endTime);
|
||
if (res.timestamp >= res.data.endTime) { //请求的还是上一轮的数据,重新请求
|
||
console.log('请求的还是上一轮的数据,必须重新请求');
|
||
showLoading()
|
||
timer2 = setTimeout(() => {
|
||
getNewestAct()
|
||
}, 600);
|
||
} else {
|
||
clearTimeout(timer2)
|
||
hideLoading(layerIndex)
|
||
|
||
roundId = res.data.roundId
|
||
getListItem(roundId)
|
||
|
||
// 进行下一轮时,arrTime重新置为空数组,不然在下一轮开始的时候也会执行location.reload()
|
||
if (roundIdArr.length < 2) {
|
||
roundIdArr = [roundId, roundId]
|
||
} else {
|
||
roundIdArr[0] = roundIdArr[1]
|
||
roundIdArr[1] = roundId
|
||
if (roundIdArr[0] != roundIdArr[1]) {
|
||
arrTime = []
|
||
arrTime2 = []
|
||
arrTime3 = []
|
||
}
|
||
}
|
||
|
||
|
||
userComeinTime = res.timestamp
|
||
|
||
startTime = res.data.startTime
|
||
drawStageStartTime = res.data.drawStageStartTime
|
||
showResultStageStartTime = res.data.showResultStageStartTime
|
||
endTime = res.data.endTime
|
||
console.log('获取5个时间戳的值-----', 'timestamp:', userComeinTime, 'startTime:', startTime, 'drawStageStartTime:', drawStageStartTime, 'showResultStageStartTime:', showResultStageStartTime, 'endTime:', endTime);
|
||
showView()
|
||
}
|
||
}
|
||
} else {
|
||
return toastMsg(res.message)
|
||
}
|
||
},
|
||
error (err) {
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
|
||
//不为3继续请求 为3拿数据 为4弹窗
|
||
let status
|
||
|
||
// 显示哪个界面
|
||
let $countDown
|
||
|
||
//区分倒计时到0时的区别处理的字段,处于第二阶段时isStatus2为真,处于第三阶段时isStatus3为真
|
||
let isStatus2
|
||
let isStatus3
|
||
|
||
let isSelectTab = false
|
||
let mySelect
|
||
let fragmentNum = 1;
|
||
let reg = /^[0-9]*$/
|
||
|
||
const showView = () => {
|
||
if (startTime <= userComeinTime && userComeinTime < drawStageStartTime) {
|
||
// 第一阶段
|
||
console.log('进入第一阶段');
|
||
isSelectTab = false
|
||
$('.select-time').show().siblings().hide()
|
||
$countDown = $('.select-time .count-down .count-down-num')
|
||
|
||
mySelect = sessionStorage.getItem("mySelect")
|
||
if (reg.test(mySelect)) {
|
||
$('.btn-wrap div').eq(mySelect).addClass('active').siblings().removeClass('active')
|
||
fragmentNum = parseInt($('.btn-wrap div').eq(mySelect).find('span').html())
|
||
isSelectTab = true
|
||
}
|
||
|
||
getPreviousResults(7, roundId)
|
||
showCountDown(userComeinTime, startTime, drawStageStartTime)
|
||
getUserInfo()
|
||
|
||
} else if (drawStageStartTime <= userComeinTime && userComeinTime < showResultStageStartTime) {
|
||
// 第二阶段
|
||
console.log('进入第二阶段');
|
||
|
||
$('.wait-time').show().siblings().hide()
|
||
$countDown = $('.wait-time .count-down .count-down-num')
|
||
|
||
clearTimeout(timer2s) //清除第一阶段的2s气泡定时器
|
||
time2sIndex = 0
|
||
|
||
isStatus2 = true //处于第二阶段的标识
|
||
console.log('isStatus2的值------------', isStatus2);
|
||
|
||
// $('.btn-wrap').find('div').removeClass('active')
|
||
|
||
getPreviousResults(7, roundId)
|
||
showCountDown(userComeinTime, drawStageStartTime, showResultStageStartTime)
|
||
judgeStatus()
|
||
getUserInfo()
|
||
|
||
// 播放5s动画
|
||
let player = new SVGA.Player('.wait-time');
|
||
let parser = new SVGA.Parser('.wait-time');
|
||
parser.load('./images/wait.svga', function (videoItem) {
|
||
// player.loops = 2;
|
||
player.clearsAfterStop = false;
|
||
player.setVideoItem(videoItem);
|
||
player.startAnimation();
|
||
})
|
||
|
||
} else if (showResultStageStartTime <= userComeinTime && userComeinTime < endTime) {
|
||
// 第三阶段
|
||
console.log('进入第三阶段');
|
||
$('.draw-time').show().siblings().hide()
|
||
$countDown = $('.draw-time .count-down .count-down-num')
|
||
|
||
isStatus3 = true //处于第三阶段的标识
|
||
console.log('isStatus3的值------------', isStatus3);
|
||
|
||
showCountDown(userComeinTime, showResultStageStartTime, endTime)
|
||
judgeStatus()
|
||
getUserInfo()
|
||
// getPreviousResults(5, roundId)
|
||
}
|
||
}
|
||
|
||
// 显示倒计时
|
||
let countDownTime
|
||
let deltaT
|
||
let timer
|
||
let delayTime
|
||
let interval
|
||
const showCountDown = (timestamp, startTime, endTime) => {
|
||
deltaT = ((endTime - startTime) - (timestamp - startTime)) / 1000 //12.361
|
||
if (deltaT >= 1) {
|
||
interval = 1
|
||
} else {
|
||
interval = 0
|
||
}
|
||
console.log('deltaT----------', deltaT);
|
||
countDownTime = Math.floor(deltaT) //12.361 => 12
|
||
delayTime = deltaT - countDownTime //请求接口的延迟时间
|
||
|
||
$countDown.html(countDownTime)
|
||
|
||
timer = setInterval(() => {
|
||
if (browser.ios) {
|
||
if (!isStatus3 && !isStatus2) {
|
||
// 处理第一阶段
|
||
if (arrTime.length < 2) {
|
||
arrTime = [new Date().getTime(), new Date().getTime()]
|
||
} else {
|
||
arrTime[0] = arrTime[1]
|
||
arrTime[1] = new Date().getTime()
|
||
// console.log('第一阶段两个时间差是多少-----',(arrTime[1] - arrTime[0])/1000);
|
||
if ((arrTime[1] - arrTime[0]) / 1000 > 1.5) {
|
||
window.location.reload()
|
||
}
|
||
}
|
||
} else if (isStatus2) {
|
||
// 第二阶段也要处理
|
||
if (arrTime2.length < 2) {
|
||
arrTime2 = [new Date().getTime(), new Date().getTime()]
|
||
} else {
|
||
arrTime2[0] = arrTime2[1]
|
||
arrTime2[1] = new Date().getTime()
|
||
// console.log('第二阶段两个时间差是多少-----',(arrTime2[1] - arrTime2[0])/1000);
|
||
if ((arrTime2[1] - arrTime2[0]) / 1000 > 1.5) {
|
||
window.location.reload()
|
||
}
|
||
}
|
||
} else if (isStatus3) {
|
||
// 第三阶段也要处理
|
||
if (arrTime3.length < 2) {
|
||
arrTime3 = [new Date().getTime(), new Date().getTime()]
|
||
} else {
|
||
arrTime3[0] = arrTime3[1]
|
||
arrTime3[1] = new Date().getTime()
|
||
// console.log('第三阶段两个时间差是多少-----',(arrTime3[1] - arrTime3[0])/1000);
|
||
if ((arrTime3[1] - arrTime3[0]) / 1000 > 1.5) {
|
||
window.location.reload()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
countDownTime--
|
||
if (countDownTime <= 0) {
|
||
$countDown.html(0)
|
||
clearInterval(timer)
|
||
|
||
if (isStatus2) { // 倒计时为0时,处于第二阶段的处理
|
||
if (status) {
|
||
// hideLoading(layerIndex)
|
||
setTimeout(() => {
|
||
getNewestAct()
|
||
}, delayTime * 1000)
|
||
isStatus2 = false
|
||
} else {
|
||
showLoading()
|
||
// toastMsg('服务器繁忙,请稍等')
|
||
console.log('status的值-----------', status);
|
||
judgeStatus()
|
||
|
||
}
|
||
} else if (isStatus3) { //倒计时为0时,处于第三阶段的处理
|
||
setTimeout(() => {
|
||
getNewestAct()
|
||
// getListItem(roundId)
|
||
}, delayTime * 1000)
|
||
// getNewestAct()
|
||
// getListItem()
|
||
isStatus3 = false
|
||
} else {
|
||
setTimeout(() => {
|
||
getNewestAct()
|
||
}, delayTime * 1000)
|
||
}
|
||
|
||
|
||
// else {
|
||
// setTimeout(() => {
|
||
// getNewestAct()
|
||
// }, delayTime * 1000)
|
||
// }
|
||
|
||
} else {
|
||
$countDown.html(countDownTime)
|
||
}
|
||
}, interval * 1000)
|
||
}
|
||
|
||
//判断status的状态
|
||
let timer4
|
||
let drawInfo
|
||
let img //第三阶段的中奖动物img
|
||
|
||
const judgeStatus = () => {
|
||
console.log('进入二阶段时轮询查看结果是否已经出了');
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/act/luckySea/getNewestAct',
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
console.log('res.data的值------------', res.data);
|
||
if ($.isEmptyObject(res.data) || res.data.status === 4) {
|
||
console.log('程序崩了!!!');
|
||
return showLoading('服务器正在维护中...')
|
||
} else if (res.data.status === 3) {
|
||
clearTimeout(timer4)
|
||
status = true
|
||
if (isStatus2 && countDownTime <= 0) {
|
||
showCountDown(userComeinTime, drawStageStartTime, showResultStageStartTime)
|
||
}
|
||
// hideLoading(layerIndex)
|
||
console.log('status为3时返回的数据--------------', res.data);
|
||
drawInfo = res.data
|
||
img = res.data.drawImageUrl
|
||
if (isStatus3) {
|
||
getPreviousResults(7, roundId)
|
||
}
|
||
renderDrawInfo()
|
||
} else {
|
||
|
||
timer4 = setTimeout(() => {
|
||
judgeStatus()
|
||
}, 1000)
|
||
|
||
}
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
},
|
||
error (err) {
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
|
||
// 渲染开奖信息
|
||
let topThreeArr = []
|
||
const renderDrawInfo = () => {
|
||
if (isStatus3) {
|
||
if (drawInfo.userDrawResult.drawStatus === 1) {
|
||
toastMsg(`恭喜你猜中啦,本轮获得${drawInfo.userDrawResult.prizeDiamonds}钻石!`)
|
||
} else if (drawInfo.userDrawResult.drawStatus === 2) {
|
||
toastMsg('很遗憾本轮没有猜中~')
|
||
}
|
||
}
|
||
let s = `
|
||
<span></span>
|
||
<div class="top-three-list">
|
||
</div>
|
||
`
|
||
$('.top-three').html(s)
|
||
|
||
$('.draw-pic img').attr('src', drawInfo.drawImageUrl)
|
||
// 渲染前三名
|
||
topThreeArr = drawInfo.rankUserList
|
||
let str = ''
|
||
if (topThreeArr.length === 0) {
|
||
// 无人猜中
|
||
$('.top-three').addClass('no-one')
|
||
$('.top-three').html('<span>本轮无人猜中</span>')
|
||
} else if (topThreeArr.length === 1) {
|
||
$('.top-three').removeClass('no-one')
|
||
$('.top-three span').html('本轮第一名')
|
||
topThreeArr.map((item) => {
|
||
str += `
|
||
<p><img src="${item.avatar}" alt=""></p>
|
||
`
|
||
})
|
||
$('.top-three-list').html(str)
|
||
} else if (topThreeArr.length === 2) {
|
||
$('.top-three').removeClass('no-one')
|
||
$('.top-three span').html('本轮前两名')
|
||
topThreeArr.map((item) => {
|
||
str += `
|
||
<p><img src="${item.avatar}" alt=""></p>
|
||
`
|
||
})
|
||
$('.top-three-list').html(str)
|
||
} else {
|
||
$('.top-three').removeClass('no-one')
|
||
$('.top-three span').html('本轮前三名')
|
||
topThreeArr.map((item) => {
|
||
str += `
|
||
<p><img src="${item.avatar}" alt=""></p>
|
||
`
|
||
})
|
||
$('.top-three-list').html(str)
|
||
}
|
||
}
|
||
|
||
// 获取每一轮抽奖的相关配置
|
||
let listItem = []
|
||
const getListItem = (roundId) => {
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/act/luckySea/listItem',
|
||
data: {
|
||
roundId
|
||
},
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
listItem = res.data
|
||
renderListItem()
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
},
|
||
error (err) {
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
|
||
// 2s气泡定时器
|
||
let timer2s
|
||
let time2sIndex = 0
|
||
const setTimeout2s = () => {
|
||
clearTimeout(timer2s)
|
||
$('.bubble-2s').eq(time2sIndex).fadeIn(50)
|
||
timer2s = setTimeout(function () {
|
||
$('.bubble-2s').eq(time2sIndex).fadeOut(50)
|
||
if (time2sIndex >= listItem.length - 1) {
|
||
time2sIndex = 0
|
||
} else {
|
||
time2sIndex++;
|
||
}
|
||
setTimeout2s()
|
||
}, 2000)
|
||
}
|
||
|
||
// 渲染每一轮抽奖的选项
|
||
const renderListItem = () => {
|
||
let str = ''
|
||
listItem.map((item) => {
|
||
str += `
|
||
<li data-total-num={"number":"${item.costPieceNum}","id":"${item.id}"}>
|
||
<img src="${item.imgUrl}" alt="">
|
||
<div class="multiple">x${item.multiple}</div>
|
||
<div class="name">${item.name}</div>
|
||
<div class="bubble-2s">
|
||
<p class="second-line"><span>${item.multiple}</span>倍奖励</p>
|
||
</div>
|
||
<div class="select-num">${item.costPieceNum === 0 ? '' : '+ ' + item.costPieceNum}</div>
|
||
</li>
|
||
`
|
||
})
|
||
$('.game-area').find('ul').html(str)
|
||
setTimeout2s()
|
||
}
|
||
|
||
// 获取往轮游戏结果
|
||
let previousResults = []
|
||
const getPreviousResults = (count, roundId) => {
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/act/luckySea/listLuckySeaActInfo',
|
||
data: {
|
||
count,
|
||
roundId
|
||
},
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
previousResults = res.data
|
||
renderPreviousResults()
|
||
}
|
||
},
|
||
error (err) {
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
|
||
// 渲染往轮游戏结果
|
||
const renderPreviousResults = () => {
|
||
|
||
let str = ''
|
||
if (previousResults.length < 5) {
|
||
let len = 5 - previousResults.length
|
||
let arr = new Array(len).fill(1)
|
||
previousResults.push(...arr)
|
||
}
|
||
if (isStatus3) {
|
||
if (img) {
|
||
previousResults.pop()
|
||
previousResults.unshift({
|
||
drawImageUrl: img
|
||
})
|
||
console.log(previousResults);
|
||
}
|
||
|
||
}
|
||
previousResults.map((item) => {
|
||
str += `
|
||
<p><img src="${item.drawImageUrl}" alt=""></p>
|
||
`
|
||
})
|
||
$('.result-list').html(str)
|
||
}
|
||
|
||
// 发送用户抽奖数量
|
||
const sendUserDrawInfo = (itemId, num) => {
|
||
networkRequest({
|
||
type: 'POST',
|
||
url: urlPrefix + '/act/luckySea/draw',
|
||
// contentType: 'application/json',
|
||
// data: `[ {
|
||
// "itemId":${itemId},
|
||
// "num":${num}
|
||
// }]`,
|
||
data: { itemId, num },
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
},
|
||
error (err) {
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
|
||
$(function () {
|
||
getInfoFromClient()
|
||
setTimeout(function () {
|
||
// getUserInfo()
|
||
getNewestAct()
|
||
// getListItem()
|
||
}, 50)
|
||
|
||
// 监听按钮点击事件
|
||
// let fragmentNum
|
||
// let isSelectTab = false
|
||
$('.btn-wrap').on('click', 'div', function () {
|
||
$(this).addClass('active').siblings().removeClass('active')
|
||
fragmentNum = parseInt($(this).find('span').html())
|
||
isSelectTab = true
|
||
sessionStorage.setItem("mySelect", $(this).index())
|
||
})
|
||
// 点击更多按钮
|
||
$('.wrap .previous-result .more').click(function () {
|
||
window.location.href = './result.html?roundId=' + roundId
|
||
})
|
||
// 监听规则按钮点击事件
|
||
$('.rule').on('click', function () {
|
||
$('.shade-mask').show()
|
||
})
|
||
// 关闭规则弹窗
|
||
$('.shade-mask').on('click', function () {
|
||
$(this).hide()
|
||
})
|
||
$('.shade-content').on('click', function (e) {
|
||
e.stopPropagation()
|
||
})
|
||
// 监听游戏记录按钮点击事件
|
||
$('.record').on('click', function () {
|
||
window.location.href = './record.html'
|
||
})
|
||
// 监听今日排名按钮点击事件
|
||
$('.rank').on('click', function () {
|
||
window.location.href = './rank.html'
|
||
})
|
||
// 跳转特权商城
|
||
$('.mall').on('click', function () {
|
||
window.location.href = './mall.html'
|
||
})
|
||
// 播放5s动画
|
||
// let player = new SVGA.Player('.wait-time');
|
||
// let parser = new SVGA.Parser('.wait-time');
|
||
// parser.load('./images/wait.svga', function(videoItem){
|
||
// // player.loops = 2;
|
||
// player.clearsAfterStop = false;
|
||
// player.setVideoItem(videoItem);
|
||
// player.startAnimation();
|
||
// })
|
||
|
||
// 播放3s动画
|
||
let player1 = new SVGA.Player('.draw-time');
|
||
let parser1 = new SVGA.Parser('.draw-time');
|
||
parser1.load('./images/draw.svga', function (videoItem) {
|
||
// player.loops = 2;
|
||
player1.clearsAfterStop = false;
|
||
player1.setVideoItem(videoItem);
|
||
player1.startAnimation();
|
||
})
|
||
// 点击海鲜动物的动画以及发送请求
|
||
$('.select-time ul').on('click', 'li', function () {
|
||
// if(!isSelectTab){
|
||
// return toastMsg('请先选择碎片数量')
|
||
// }
|
||
if (myFragment < fragmentNum) {
|
||
return toastMsg('碎片不足,请前往右上角特权商城获取')
|
||
}
|
||
|
||
if (!lock) {
|
||
lock = !lock
|
||
console.log($(this).data('total-num'));
|
||
$(this).data('total-num').number = parseInt($(this).data('total-num').number) + fragmentNum
|
||
$(this)
|
||
.stop(true, true)
|
||
.animate({ scale: 1.1 }, 200)
|
||
.animate({ scale: 1 }, 200, function () {
|
||
if (lock) {
|
||
$(this).find('.select-num').html('+' + $(this).data('total-num').number).hide().fadeIn(200)
|
||
}
|
||
setTimeout(() => {
|
||
// getUserInfo()
|
||
getUserPieceNum()
|
||
// getListItem(roundId)
|
||
}, 100)
|
||
})
|
||
sendUserDrawInfo($(this).data('total-num').id, fragmentNum)
|
||
}
|
||
})
|
||
|
||
// ios去到后台或者锁屏后再回来倒计时不准确
|
||
let leftTime, deltaTime, startTime, endTime
|
||
document.addEventListener('visibilitychange', function () {
|
||
if (document.visibilityState == 'hidden') {
|
||
leftTime = countDownTime
|
||
startTime = new Date().getTime()
|
||
} else if (document.visibilityState == 'visible') {
|
||
endTime = new Date().getTime()
|
||
deltaTime = Math.floor((endTime - startTime) / 1000) //出去了多久
|
||
if (deltaTime > 300) {
|
||
window.location.reload()
|
||
}
|
||
countDownTime = leftTime - deltaTime
|
||
if (countDownTime < 0) {
|
||
countDownTime = 0
|
||
}
|
||
$countDown.html(countDownTime)
|
||
}
|
||
})
|
||
})
|