Home  >  Article  >  Web Front-end  >  JavaScript code sharing to implement event countdown effect

JavaScript code sharing to implement event countdown effect

黄舟
黄舟Original
2017-04-24 09:21:031440browse

This article mainly introduces in detail the event countdown effect based on JavaScript, how much time is left until the event, it has certain reference value, interested friends can refer to it

The example in this article shares the specific code of jscountdown effect for your reference. The specific content is as follows

<!DOCTYPE html> 
<html> 
  <head> 
    <title>countDown</title> 
    <style type="text/css"> 
      #myp{ 
        width:150px; 
        background-color:green; 
        margin:0 auto; 
        padding:0 auto; 
        color:pink; 
      } 
    </style> 
    <script type="text/javascript"> 
      <!-- 秒数可修改--> 
      var second=50; 
      <!-- 分钟可修改--> 
      var minute=1; 
      <!-- 小时可修改--> 
      var hour=1; 
      <!-- 天数可修改--> 
      var day=1; 
      var flag=false; 
      function countDown(){ 
        var p=document.getElementById("myp"); 
        second-=1; 
        if(second==0){ 
          minute=minute-1; 
          second=60; 
          if(minute<0){ 
            hour=hour-1; 
            minute=59; 
            if(hour<0){ 
              day-=1; 
              hour=23; 
              if(day<0){ 
                flag=true; 
              } 
            } 
          } 
        } 
        if(flag){ 
          p.innerHTML="活动结束!"; 
        }else{ 
          p.innerHTML="距离活动时间还剩:"+day+"天"+hour+"小时"+minute+"分"+second+"秒"; 
        } 
      } 
       setInterval("countDown()",1000); 
    </script> 
  </head> 
  <body> 
    <p id="myp">倒计时</p> 
  </body> 
</html>

The above is the detailed content of JavaScript code sharing to implement event countdown effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn