Summary of countdown effect examples implemented by jQuery_jquery
The example in this article summarizes the countdown effect implemented by jQuery. Share it with everyone for your reference, the details are as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Jquery实现倒计时效果</title> <script language="javascript" src="jquery-1.3.2.min.js"></script> <script type="text/javascript"> var SysSecond; var InterValObj; $(document).ready(function() { SysSecond = parseInt($("#remainSeconds").html()); //这里我是在服务端算好了剩余的秒数,并保存到客户端,如果过期则返回0 InterValObj = window.setInterval(SetRemainTime, 1000); //间隔函数,1秒执行 }); //代理,接单的时间+1小时减去当前时间的秒数 function SetRemainTime() { if (SysSecond > 0) { //alert(SysSecond); SysSecond = SysSecond - 1; var second = Math.floor(SysSecond % 60); // 计算秒 var minite = Math.floor((SysSecond / 60) % 60); //计算分 var hour = Math.floor((SysSecond / 3600) % 24); //计算小时 var day = Math.floor((SysSecond / 3600) / 24); //计算天 $("#remainTime").html(day + "天" + hour + "小时" + minite + "分" + second + "秒"); } else {//剩余时间小于或等于0的时候,就停止间隔函数 window.clearInterval(InterValObj); } } </script> </head> <body> <div id="remainSeconds" style="display:none">18000</div> <div id="remainTime" style="font-size:20px;font-weight:800;color:#FF9900"></div> </body> </html>
After we read the time field in the database in the webservice, we divide the time into judgments. The Javascript code is as follows:
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> function Times() { var tempTime=document.getElementById("currTime").innerHTML.split(":"); var hour=tempTime[0]; var minute=tempTime[1]; var second=tempTime[2]; if(second>=1) { second=(second-1>9)?(second-1):"0"+(second-1); } else { second="59"; if(minute>=1){ minute=(minute-1>9)?(minute-1):"0"+(minute-1); }else{ minute="59"; if(hour>=1){ hour=(hour-1>9)?(hour-1):"0"+(hour-1); }else{ minute="00"; hour="0"+0; } } } document.getElementById("currTime").innerHTML=hour+":"+minute+":"+second; if(hour==0&&minute==0&&second==0) { document .getElementById ("currTime").style .display ="none"; } else setTimeout (Times,1000); } //当窗体加载是调用。相当于onload()事件 (function gettime() { $.ajax({ contentType:"application/json", type: "POST", url: "WebService.asmx/Gettime", data: "{'id':'1'}", dataType: 'json', success: function(msq){ document .getElementById ("currTime").innerHTML =msq.d ; } }); setTimeout (Times,1000) ; })(); </script>
Multiple countdowns>>>
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <p>离一模还有<span id="_lefttime1" style="color:red;font-size:12pt;"></span></p> <p>离二模还有<span id="_lefttime2" style="color:red;font-size:12pt;"></span></p> <p>离高考还有<span id="_lefttime3" style="color:red;font-size:12pt;"></span></p> </body> </html> <SCRIPT LANGUAGE="JavaScript"> function _fresh(){ var datalist =new Array(); datalist =[ [new Date("2010/10/1"), "_lefttime1"], [new Date("2010/10/15"), "_lefttime2"], [new Date("2010/10/2"), "_lefttime3"] ]; for(var i =0; i<datalist.length; i++){ var endtime =datalist[i][0]; var nowtime = new Date(); var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000); if(leftsecond<0)leftsecond=0; var __d=parseInt(leftsecond/3600/24); document.getElementById(datalist[i][1]).innerHTML=__d+"天 "; } } setInterval(_fresh,1000); </SCRIPT>
Readers who are interested in more jQuery-related content can check out the special topics on this site: "JQuery date and time operation skills summary", "jQuery switching special effects and skills summary", "JQuery Drag and Drop Special Effects and Skills Summary", "jQuery Extension Skills Summary", "jQuery Common Classic Special Effects Summary", "jQuery Animation and Summary of special effects usage ", "jquery selector usage summary " and "jQuery common plug-ins and usage summary "
I hope this article will be helpful to everyone in jQuery programming.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

In win10, the boot countdown is enabled by default. When we turn on the computer, we will see a countdown interface, usually a 10-second countdown. Within this time, we can choose whether to continue booting or perform some other operations. Although the boot countdown brings some convenience to our system, it may also cause trouble in some cases. I want to cancel the display, but I don’t know how to do it. This article brings you how to cancel the countdown of several seconds after booting up Win10. Understand the win10 boot countdown. In win10, the boot countdown is enabled by default. When we turn on the computer, we will see a countdown interface, usually a 10-second countdown. Within this time, we can choose whether to continue booting or proceed

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
