jQuery倒计时插件

Countdown timer jQuery Plugin 本文以v1.2为例

 


 

这是一个简单易用的倒计时插件,不过默认的例子,在Firefox和IE下边都没有效果,Chrome正常。demo代码如下:

 

$(document).ready(function() {
	
	$("#time").countdown({
		date: "july 1, 2011 19:24",
		onChange: function( event, timer ){
		
			/*
				Tips:
				
				event.target is DOM Element
				this is DOM element
				$(this) is jQuery Element
				timer is interval for countdown
				
				If a countdown should end early you could do:
				
				clearInterval( timer );
				$(this).trigger('complete');
			*/

		},
		onComplete: function( event ){
		
			$(this).html("Completed");
		},
		leadingZero: true
	});

});

 

 

查看插件的源代码,发现问题出在date这个参数的设置,在源代码中使用new Date(opts.date)来创建时间。多次尝试发现,配合Rails使用的时候很方便:

 

    $(document).ready(function() {

      $("#time>").countdown({
        date: "<%= product.end_time.to_formatted_s(:rfc822) %>",
        htmlTemplate: "%{d} <span class=\"small\">天</span> %{h} <span class=\"small\">小时</span> %{m} <span class=\"small\">分钟</span> %{s} <span class=\"small\">秒</span>",
        onComplete: function( event ){
          $(this).html("已结束");
        },
        leadingZero: true
      });

    });

 其中

 

date: "<%= product.end_time.to_formatted_s(:rfc822) %>"

 生成类似

 

date: "Mon, 12 Sep 2011 18:00:00 +0800"
 

 

 

更多插件http://paranimage.com/9-countdown-cool-jquery-plugins-and-tutorials/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值