In actual projects, a countdown flash sale function is required. After 6 pm every day, the hours, minutes and seconds are calculated from 10 am the next day, and the snap-up function is activated after 10 am the next day; the code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="js/jquery-1.11."></script> </head> <body οnlοad="leftTimer();"> <p class="tit_right" style=""> <span style="">00</span> <span style="">00</span> <span style="">00</span> </p> <p style="" ></p> <script> function leftTimer(year,month,day,hour,minute,second){ var newDate = new Date(); var newDate1 = new Date(year,month-1,day,hour,minute,second); var leftTime = (new Date(year,month-1,day,hour,minute,second)) - (new Date()); //Calculate the remaining milliseconds var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //Calculate the remaining days var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //Calculate the remaining hours var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//Calculate the remaining minutes var seconds = parseInt(leftTime / 1000 % 60, 10);//Calculate the remaining seconds if (seconds<0) { $(".tit_right").css('display', 'none'); $("#juli").text("Start snap-up"); } else{ days = fix(days,2); hours = fix(hours,2); minutes = fix(minutes,2); seconds = fix(seconds,2); setTimeout("leftTimer(2017,2,21,11,0,0)",1000); ("h").innerHTML=hours; yId("m").innerHTML=minutes; ("s").innerHTML=seconds; } } //fix function: convert 1 digits from 1 to 9 into 01 to 09 format function fix(num, length) { return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num; } </script> </body> </html>
The above is passed in the leftTimer() function. The parameters are the specified date and time, and the timing is turned on!
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.