jquery倒计时插件
Html页面的调用方法代码:
- <!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>
- <title></title><!--http://www.cssrain.cn/demo/jquery-ui-tab/jquery-1.3.1.js-->
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script src="jquery-1.4.2.js" type="text/javascript"></script>
- <script src="time.js" type="text/javascript"></script>
- <script>
- $(function(){
- /***** 测试1 ****/
- // 开始 && 重新开始
- $("#start").click(function(){
- $("#test").CRcountDown({
- startNumber:15,
- callBack:test
- })
- .css("color","red");
- });
- // 暂停
- $("#pause").click(function(){
- $("#test").pause();
- });
- // 暂停后 重新开始
- $("#again").click(function(){
- $("#test").reStart();
- });
- function test(){
- $("<p>1</p>")
- .hide()
- .fadeIn(1000)
- .appendTo("body");
- }
- /***** 测试2 ****/
- // 开始 && 重新开始
- $("#start2").click(function(){
- $("#test2").CRcountDown({
- startNumber:10,
- callBack:test2
- })
- .css("color","blue");
- });
- // 暂停
- $("#pause2").click(function(){
- $("#test2").pause();
- });
- // 暂停后 重新开始
- $("#again2").click(function(){
- $("#test2").reStart();
- });
- function test2(){
- $("<p>2</p>")
- .hide()
- .fadeIn(1000)
- .appendTo("body");
- }
- })
- </script>
- </head>
- <body>
- <h1>测试1:</h1>
- <button id="start" >开始&&重新开始</button>
- <button id="pause" >暂停</button>
- <button id="again" >暂停后 重新开始</button>
- <div id="test" ></div>
- <br/>
- <h1>测试2:</h1>
- <button id="start2" >开始&&重新开始</button>
- <button id="pause2" >暂停</button>
- <button id="again2" >暂停后 重新开始</button>
- <div id="test2" ></div>
- <br/><br/>
- Dev by cssrain
- </body>
- </html>
复制代码time.js的代码:
- $(function(){
- jQuery.fn.countDown = function(settings,to) {
- if(!to && to != settings.endNumber) { to = settings.startNumber; }
- this.data("CR_currentTime",to);
- $(this).text(to).animate({"none":"none"},settings.duration,'',function() {
- if(to > settings.endNumber + 1) {
- $(this).countDown(settings,to - 1);
- }else{
- settings.callBack(this);
- }
- });
- return this;
- };
- //计时&&重新计时
- jQuery.fn.CRcountDown = function(settings) {
- settings = jQuery.extend({
- startNumber: 10,
- endNumber: 0,
- duration: 1000,
- callBack: function() { }
- }, settings);
- this.data("CR_duration",settings.duration);
- this.data("CR_endNumber",settings.endNumber);
- this.data("CR_callBack",settings.callBack);
- return this.stop().countDown(settings);
- };
- //计时暂停
- jQuery.fn.pause = function(settings) {
- return this.stop();
- };
- //暂停后,重新开始
- jQuery.fn.reStart = function() {
- return this.pause().CRcountDown({
- startNumber : this.data("CR_currentTime"),
- duration : this.data("CR_duration"),
- endNumber : this.data("CR_endNumber"),
- callBack : this.data("CR_callBack")
- });
- };
- })
复制代码
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论