countdown怎么用,jqueryh5时间

文章 2年前 (2021) admin
0
countdown怎么用,jqueryh5时间

Q1:jQuery Countdown 获取的是服务时间还是本地时间

是本地页面时间,前端一般获取的都是本地时间。JQuery CountDown里面都是通过new Date的方式和setInterval定时方式进行的。一般countdown的初始时间最好是从服务器给定,然后倒计时。

Q2:jquery.countdown插件为什么会出现两个倒计时

代码内容:* { margin: 0; padding: 0; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; -ms-box-sizing: border-box; -o-box-sizing: border-box; box-sizing: border-box; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;}

Q3:countdown.js 判断倒计时怎么结束

是本地页面时间,前端一般获取本地时间。JQuery倒计时是通过新的日期和设置时间间隔的方式来完成的。一般最好从服务器给出倒计时的初始时间,然后倒计时。

Q4:jquery倒计时 设定的时间到了,不执行了。怎么写?

var range = NY-Math.round((new Date()).getTime()/1000).....if(range>0){return nol(days)+" "+nol(hours)+" "+nol(min)+" "+nol(sec);}else{$("#new_year").html("已经结束");}加个判断试试,当range小于0时就是结束吧,要该时间就是改这里吧var NY = Math.round((new Date("3/08/2015 21:00:00")).getTime()/1000);

Q5:jquery jcountdown怎么加

1.使用: $("#clock").countdown(finalData[, callback(或options)]); finalData - 必选 options - 可选 2.参数: 1>finalData - 设置倒计时的终止时间 3种格式: 1)原生的 "Date" 对象 2)毫秒格式的 "时间戳"(javascript的时间戳,单位是 "毫秒",切记!) matchers.push(/^[0-9]*$/.source); 源码中的正则: matchers.push(/^[0-9]*$/.source); 3)字符串格式的时间 YYYY/MM/DD MM/DD/YYYY YYYY/MM/DD hh:mm:ss MM/DD/YYYY hh:mm:ss 源码中的正则: matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); 2>callback(或options) - 回调函数 或者 options 对象 1)callback - 倒计时,有3个事件类型,都绑定上回调方法! function(event) {} 源码分析: this.$el.on("update.countdown", options); this.$el.on("stoped.countdown", options); this.$el.on("finish.countdown", options); 2)options - 传递一个对象,覆盖 "countdown" 的默认配置,默认配置有3个: defaultOptions = { precision: 100, //int - 更新速率(毫秒为单位) elapse: false, //bool - 倒计时结束后,是否继续 defer: false //bool - 延迟初始化模式 } 1.precision - 倒计时的精度 源码分析: this.interval = setInterval(function() { self.update.call(self); }, this.options.precision); //setInterval()的第二个参数 2.elapse - 过期模式 false - 一旦到达设定的最终时间,停止计时。(默认) true - 到达最终时间,继续执行倒计时。 源码分析: if (!this.options.elapse && this.totalSecsLeft === 0) { //到达最终事件 this.stop(); //停止计时 this.dispatchEvent("finish"); //分发 "finish" 事件 } else { this.dispatchEvent("update"); //分发 "update" 事件 } -------- 一旦到达终止时间,会传递给事件对象,一个属性: event.elapsed - 是否已经过期 this.elapsed = now >= this.finalDate; 3.defer - 是否延迟启动 false - 表示初始化了 "倒计时对象",会自动开始计时。(默认) true - 在实例化对象后,需要我们来手动启动计时。 源码分析: if (this.options.defer === false) { this.start(); } 3.事件: 3个事件方法: update.countdown finish.countdown stoped.countdown //这个得说明下,文档中,应该是错误的!源码中是:"stoped",文档中写的是 "stop" 3个事件,都有一个 "namespace-命名空间",".countdown" 每个事件对象,具备额外的公共属性: event.finalDate = this.finalDate; //设定的终止时间 event.elapsed = this.elapsed; //是否已经过期 event.offset = $.extend({}, this.offset); //当前时间,在各个时间刻度上的计算 源码分析: this.offset = { seconds: this.totalSecsLeft % 60, minutes: Math.floor(this.totalSecsLeft /60) % 60, hours: Math.floor(this.totalSecsLeft /60 /60) % 24, days: Math.floor(this.totalSecsLeft /60 /60 /24) % 7, daysToWeek: Math.floor(this.totalSecsLeft /60 /60 /24) % 7, daysToMonth: Math.floor(this.totalSecsLeft /60 /60 /24 % 30.4368), weeks: Math.floor(this.totalSecsLeft /60 /60 /24 /7), weeksToMonth: Math.floor(this.totalSecsLeft /60 /60 /24 /7) % 4, months: Math.floor(this.totalSecsLeft /60 /60 /24 /30.4368), years: Math.abs(this.finalDate.getFullYear() - now.getFullYear()), totalDays: Math.floor(this.totalSecsLeft /60 /60 /24), totalHours: Math.floor(this.totalSecsLeft /60 /60), totalMinutes: Math.floor(this.totalSecsLeft /60), totalSeconds: this.totalSecsLeft }; event.strftime = strftime(this.offset); //格式化时间函数 源码分析: function strftime(offsetObject) { return function(format) { /* 匹配指令: %-字母 %!字母 %字母 %字母:其它字符; */ var directives = format.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi); if (directives) { //对匹配到的每个指令,进行解析 for (var i = 0, len = directives.length; i < len; ++i) { var directive = directives[i].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/), regexp = escapedRegExp(directive[0]), //正则 modifier = directive[1] || "", //模式:- | ! | "" plural = directive[3] || "", //:其他字符; ------ 和 "!" 模式一起使用 value = null; directive = directive[2]; //表示时间刻度的字母(Y,m,n,d,w...) //匹配到了该字母对应的时间值,进行字符替换 if (DIRECTIVE_KEY_MAP.hasOwnProperty(directive)) { value = DIRECTIVE_KEY_MAP[directive]; value = Number(offsetObject[value]); } if (value !== null) { //"!"模式,执行 "pluralize",会需要 "(:[^;]+;)" 匹配到的值 if (modifier === "!") { value = pluralize(plural, value); } //""模式,小于10,填充 "0" if (modifier === "") { if (value 1,返回复数格式,否则为单数 if (Math.abs(count) > 1) { return plural; } else { return singular; } } 4.event.strftime - 格式化函数,是一个简单的格式化程序,有助于保持代码更加语义,并且避免重复的工作。 它根据给定格式字符串中的指令来格式化偏移日期。 该指令由百分比(%)组成。 未列为指令的任何文本将被传递到输出字符串。 event.strftime(%W weeks %-d days %-H h %M min %S sec"); /* Y: "years", m: "months", n: "daysToMonth", d: "daysToWeek", w: "weeks", W: "weeksToMonth", H: "hours", M: "minutes", S: "seconds", D: "totalDays", I: "totalHours", N: "totalMinutes", T: "totalSeconds" */ 所有的指令,包含0填充(01,02,03)和空白填充"1,2,3"版本,默认是0填充,不需要0填充,使用-%D。 - 模式: - //空白填充 ! //多元化复数模式 默认:复数添加 "s",单数不变 %!H //当 hour>1,结尾添加 "s" %!H:hours //当 hour>1,结尾添加 "hours" %!H:hour,hours; //当 hour>1,结尾添加 "hours",hour3个事件方法: update.countdown finish.countdown stoped.countdown 2>每个事件的额外属性: event.finalDate = this.finalDate; //设定的终止时间 event.elapsed = this.elapsed; //是否已经过期 event.offset = $.extend({}, this.offset); //当前时间,在各个时间刻度上的计算 event.strftime = strftime(this.offset); //格式化时间函数 示例: $("#countdown").countdown("2017/5/1") .on("update.countdown", function(){ format = "还剩%D天, %H时, %M分, %S秒开始抽奖"; //指定格式字符串 $(this).html(event.strftime(format)); //将格式字符串,传递给 "event.strftime()" 解析 }) .on("finish.countdown", function(){ $(this).html("开始抽奖"); });

Q6:求教jquery倒计时,可刷新的

从服务器请求时间。存cookie用html5中的存储方法 localStorage  然后我发给你个 倒计时代码,但是没有设置 存储! ul, li { list-style: none; margin: 0; padding: 0; } .cz-timekeepingContainer { height: 52px; padding: 0 20px; background: #e01222; font-size: 12px; color: #FFFFFF; } .cz-timekeepingContainer .timeTitle { margin-top: 20px; } .cz-timekeepingContainer .timeIm { margin-top: 20px; } .cz-timekeepingContainer .timeIm ul { margin: 0 6px; margin-top: -13px; } .cz-timekeepingContainer .timeIm ul li { float: left; } .cz-timekeepingContainer .timeIm ul .timeNum { background: #440106; border-radius: 2px; text-align: center; line-height: 38px; color: #E01222; font-size: 22px; font-weight: 600; padding: 0 6px; } .cz-timekeepingContainer .timeIcon { width: 12px; height: 16px; margin-top: 8px; } .cz-timekeepingContainer .timeIcon span { width: 4px; height: 4px; border-radius: 100%; background: #440106; display: block; margin: auto; margin-top: 4px; }

总有你想不到的价格
还有
  • 00
  • 00
  • 00
结束抢购

!(function($) { var CZCountDown = function (element, options) { this.$ = $(element); this.options = this.getOptions(options); this.init(); this.timer = null; }; CZCountDown.DEFAULTS =  { time : getDefaulTime() }; CZCountDown.prototype.getOptions = function (options) { options = $.extend({}, CZCountDown.DEFAULTS, options); return options; }; CZCountDown.prototype.init = function () { var timeReg = /\d{4}(\-)\d{1,2}(\-)\d{1,2}\s\d{1,2}(\:)\d{1,2}(\:)\d{1,2}/; if( !timeReg.test(this.options.time)) { alert("填写日期格式不对") }; var time = new Date(this.options.time); var time = time.getTime(); this.formatTime(time); } CZCountDown.prototype.formatTime = function (time) { var self = this; var nowTime = +new Date(); this.time = time; clearTimeout(this.timer); if( (time - nowTime) > 0 ) { this.timer = setTimeout(function () { self.formatTime(self.time); }, 1000); timeNum = czFormatTime(time - nowTime); czSethtml(timeNum); }else if( (time - nowTime) < 0 ) { alert("设置时间小于当前时间"); } } var czSethtml = function (val) { $(".czHours").html(val.h); $(".czMinuts").html(val.m); $(".timeSecond").html(val.s); } function getDefaulTime() { var nowDate = new Date(); var year    = nowDate.getFullYear(); var month   = nowDate.getMonth() + 1; var day     = nowDate.getDate(); var H       = nowDate.getHours() + 1; var M     = nowDate.getMinutes(); var S = nowDate.getSeconds(); var defaulDate = [year, month, day]; var defaulDate = defaulDate.join("-"); var defaulTime = [H, M, S]; var defaulTime = defaulTime.join(":"); return time = defaulDate + " " + defaulTime; } function czCover(num) { var n = parseInt(num, 10); return n < 10 ? "0" + n : n; } function czFormatTime(ms) { var s = ms /1000,    m = s /60; return { d : czCover(m /60 /24), h : czCover(m /60 % 24), m : czCover(m % 60), s : czCover(s % 60) }; } $.fn.czCountDown = function (method) { return this.each(function () { var $this = $(this); new CZCountDown($this, method); }); } })(window.jQuery); $(".timeIm").czCountDown( { time : "2016-12-20 2:2:2" });

版权声明:admin 发表于 2021年11月16日 下午7:35。
转载请注明:countdown怎么用,jqueryh5时间 | 热豆腐网址之家

相关文章