活动h5页面倒计时效果

2017-01-13 10:53:05来源:csdn作者:sinat_29843547人点击


仅供参考逻辑

$(function(){})中的代码:

//倒计时参数
var time = [{'y':2015,'m':11,'d':11,'h':16,'min':35,'order':0},
{'y':2015,'m':11,'d':11,'h':18,'min':40,'order':1},
{'y':2015,'m':11,'d':11,'h':19,'min':45,'order':2},
{'y':2015,'m':11,'d':11,'h':20,'min':50,'order':3},
{'y':2015,'m':11,'d':11,'h':21,'min':55,'order':4},
{'y':2015,'m':11,'d':11,'h':22,'min':00,'order':5}];
fortimedecline(time);//点击参与
$('.djs-button').click(function() {
if(this.src.indexOf('djs-ok-button.png')>0){
if ( typeof (window.jsCallNativeObjc) != 'undefined') {
window.jsCallNativeObjc.showBet('');
}
//android
else if ( typeof (shareAndroid) != 'undefined') {
shareAndroid.showBet('');
}
}
});外部function():
function fortimedecline(time){
var keepgoing = true;
var index = 0;
time.forEach(function(e){
index ++;
if(keepgoing){
var addawardyear = e.y;
var addawardmonth = e.m;
var addawardday = e.d;
var addawardday_hour = e.h;
var addawardday_min = e.min;var date = new Date();
var today = date.getDate();
var today_year = date.getFullYear();
var today_month = date.getMonth();
var today_hour = date.getHours();
var today_min = date.getMinutes();
var today_sec = date.getSeconds();var show_hours = (addawardday - today)*24+(addawardday_hour-today_hour);
var show_mins = addawardday_min - today_min;
var show_secs = 59 - today_sec;var hour = show_hours;
var min = show_mins-1;
var sec = Math.abs(show_secs);if(show_mins<=0){
var hour = show_hours-1;//时-1
var min = 59+show_mins;//分+59
var sec = Math.abs(show_secs);
}
var sec_result = hour*3600+min*60+sec;
if(sec_result>=0&&addawardyear == today_year&&addawardmonth == (today_month+1)){
timedecline(hour,min,sec,e.order,time);
keepgoing = false;//退出循环
}
else{
if(index == 6){
$('#djs_title')[0].textContent = '本次加奖投注已经结束啦';
$('#djs-sec')[0].textContent = '00';
$('#djs-min')[0].textContent = '00';
$('#djs-hour')[0].textContent = '00';
change_button([2,2,2]);
}
}
}
});
}
function timedecline(hour,min,sec,order,time){
var title_arr = ["距离第一轮加奖开始还有",
"距离第一轮加奖结束还有",
"距离第二轮加奖开始还有",
"距离第二轮加奖结束还有",
"距离第三轮加奖开始还有",
"距离第三轮加奖结束还有"];
var button = {0:[0,0,0],1:[1,0,0],2:[2,0,0],3:[2,1,0],4:[2,2,0],5:[2,2,1]};for(var i=0;i<title_arr.length;i++){
if(order == i){
$('#djs_title')[0].textContent = title_arr[i];
change_button(button[i]);
}
}
$('#djs-sec')[0].textContent = timeformat(sec);
$('#djs-min')[0].textContent = timeformat(min);
$('#djs-hour')[0].textContent = timeformat(hour);
timer = setInterval(function() {
var over = false;
if (sec <= 0) {
sec = 60;
if (min <= 0) {
min = 60;
if (hour <= 0 && min <= 60 && sec <= 60) {
over = true;
clearInterval(timer);
fortimedecline(time);
} else {
hour--;
$('#djs-hour')[0].textContent = timeformat(hour);
}
}
if(!over){
min--;
$('#djs-min')[0].textContent = timeformat(min);
}
}
if(!over){
sec--;
$('#djs-sec')[0].textContent = timeformat(sec);
}
}, 1000);}
function change_button(arr){
var button = $('.djs-button');
for(var i=0;i<arr.length;i++)
{
switch(arr[i]){
case 0:
button[i].src = '../../images/djs-readystart-button.png';
break;
case 1:
button[i].src = '../../images/djs-ok-button.png';
break;
case 2:
button[i].src = '../../images/djs-over-button.png';
break;
}
}
}
function timeformat(time) {
time = String(time);
if (time.length == 1) {
time = "0" + time;
}
return time;
};效果:

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台