jQuery动态倒计时插件实例代码

发布时间:2020-03-17编辑:脚本学堂
分享一个jquery动态倒计时插件的代码,通过实例学习jquery倒计时实现方法,风格简洁的倒计时特效,初步设定数字由9——0变化,每次变化都有从大到小的动态效果。

jquery倒计时插件实例,风格简洁的倒计时特效,初步设定数字由9——0变化,每次变化都有从大到小的动态效果,也可以看作是倒数插件,把一组数字按倒序显示出来,jQuery配合javascript实现的效果。

完整代码:
 

复制代码 代码示例:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery实现的超酷倒计时、倒数插件_www.jb200.com</title>
<style type="text/css">
@media all{*{margin:0; padding:0;} html{overflow-y:scroll;}body{font-family:'lucida grande',tahoma,verdana,arial,sans-serif; font-size:62.5%;
color:#222;}.center{width:1000px; margin:0 auto;}#page{}#content{background:#fff; padding:10px 0 10px 0;}#content-left{width:700px; margin:0 20px 0 0;
float:left;}#content-right{width:280px; float:left;}#content-right a{float:left; padding-right:10px; display:block; width:125px;
height:125px;}#footer{background:#eee; border-top:1px solid #ccc; padding:10px 0;}#footer1, #footer2, #footer3{width:300px; float:left; margin:0 30px 0
0;}#footer3{width:330px; margin-right:0;}abbr{border-bottom:1px dotted #ccc; cursor:help;}blockquote{background:#eee; margin:0 20px; padding:10px
20px;}code{font-family:'Consolas', 'Monaco', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;}h1{font-size:4.3em; margin:0 0 20px
0;}h2{font-size:2.8em;}h1, h2, h3, h6{font-weight:normal; font-family:"Droid Serif",Cambria,Georgia,Palatino,"Palatino Linotype","Myriad Pro",Serif;}h3,
h6{font-size:2em;}h6{padding:0 0 5px 0;}label,select,input[type='submit'],.point{cursor:pointer;}li{}li,p{line-height:19px; margin-top:5px;}ol, ul{padding:0 0 10px
35px;}p{margin:5px 0 14px 0; font-size:1.2em; line-height:1.8em;}textarea,input[type='text'], input[type='email'], input[type='password']{border:1px solid #ccc;
padding:5px; font-size:120%; font-family:'lucida grande',tahoma,verdana,arial,sans-serif;}.clear{clear:both;}.exhead{background:#e8f0f6; border-top:1px solid #fff;
color:#000; padding:10px 10px; font-size:120%;}.exhead a{color:#6D84B4;}.intro{background:#ffd987; font-style:italic; padding:5px 10px;
margin-bottom:20px;}.relative{position:relative;}a{color:#3b5998;}a:link, a:visited{text-decoration:underline;}a:hover, a:active{text-decoration:none;}a
img{border:0;}}
</style>
<script type="text/javascript">
window.onload = function() {
 var paras = document.getElementById('content').getElementsByTagName('p');
 if(paras.length) {
  paras[0].className = paras[0].className + ' intro';
 }
};
</script> 
<script type="text/javascript" src="/ajaxjs/jquery1.3.2.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
   jQuery.fn.delay = function(time,func){
    return this.each(function(){
     setTimeout(func,time);
    });
   };
   jQuery.fn.countDown = function(settings,to) {
    settings = jQuery.extend({
     startFontSize: '36px',
     endFontSize: '12px',
     duration: 1000,
     startNumber: 10,
     endNumber: 0,
     callBack: function() { }
    }, settings);
    return this.each(function() {
     if(!to && to != settings.endNumber) { to = settings.startNumber; }
     $(this).text(to).css('fontSize',settings.startFontSize);
     $(this).animate({
      'fontSize': settings.endFontSize
     },settings.duration,'',function() {
      if(to > settings.endNumber + 1) {
       $(this).css('fontSize',settings.startFontSize).text(to - 1).countDown(settings,to - 1);
      }
      else
      {
       settings.callBack(this);
      }
     });
       
    });
   };
   $('#countdown').countDown({
    startNumber: 10,
    callBack: function(me) {
     $(me).text('All done! This is where you give the reward!').css('color','#090');
    }
   });
   
  });
 </script>
</head>
<body>
<div id="content"><div class="center">
 <div id="content-left">
  <h1 style="margin-top:20px;">jQuery CountDown Plugin Example</h1> 
 <p>
  <span id="countdown"></span>
 </p>
</div>
<div class="clear"></div>
</div></div>
</body>
</html>