hk7887 0 ارسال شده در اسفند 99 گزارش بازنشر ارسال شده در اسفند 99 سلام خسته نباشید,یک شمارش معکوس در سایتم دارم که میخوام وقتی به صفر رسید دوباره برگرده و از اول شروع به شمارش کنه یعنی :5,4,3,2,1,0 وقتی به صفر رسید دوباره بر گرده و از 5 بشماره . این کدم هست من خیلی تلاش کردم اما نتونستم همچین چیزی رو پیاده کنم از دوستان کسی بلده کمکم کنه. <div class="container"> <h1> <span class="timer" data-minutes-left="1"></span></h1> </div> <style> span.timer { display: inline-flex; } span.timer { font-size: 15px; margin-right:140px; } div.c-product-box__amazing{ display: flex; flex-direction: column; justify-content: center; height:20px; } </style> <script> ! function (t) { "object" == typeof module && "object" == typeof module.exports ? module.exports = function (e) { t(e, window, document) } : t(jQuery, window, document) }(function (t, e, n, o) { var s; Number.isFinite = Number.isFinite || function (t) { return "number" == typeof t && isFinite(t) }; var i = function (t) { return this._options = {}, this.targetElement = t, this }; i.start = function (t, e) { return function (t, e) { e = e || {}, t._options.elementContainer = e.elementContainer || "div"; var n = e.classNames || {}; t._options.classNameSeconds = n.seconds || "jst-seconds", t._options.classNameMinutes = n.minutes || "jst-minutes", t._options.classNameHours = n.hours || "jst-hours", t._options.classNameClearDiv = n.clearDiv || "jst-clearDiv", t._options.classNameTimeout = n.timeout || "jst-timeout" }(s = new i(e), t), s.start(t) }, i.prototype.start = function (e) { var o = this, i = function (t) { var e = n.createElement(o._options.elementContainer); e.className = o._options.classNameSeconds; var s = n.createElement(o._options.elementContainer); s.className = o._options.classNameMinutes; var i = n.createElement(o._options.elementContainer); i.className = o._options.classNameHours; var r = n.createElement(o._options.elementContainer); return r.className = o._options.classNameClearDiv, t.append(i).append(s).append(e).append(r) }; this.targetElement.each(function (n, o) { var r = this, a = t(o), u = a.attr("class"); return a.on("complete", function () { clearInterval(a.intervalId) }), a.on("complete", function () { a.onComplete(a) }), a.on("complete", function () { a.addClass(r._options.classNameTimeout) }), a.on("complete", function () { e && !0 === e.loop && s.resetTimer(a, e, u) }), a.on("pause", function () { clearInterval(a.intervalId), a.paused = !0 }), a.on("resume", function () { a.paused = !1, r.startCountdown(a, { secondsLeft: a.data("timeLeft") }) }), i(a), this.startCountdown(a, e) }.bind(this)) }, i.prototype.resetTimer = function (t, e, n) { var o = 0; e.loopInterval && (o = 1e3 * parseInt(e.loopInterval, 10)), setTimeout(function () { t.trigger("reset"), t.attr("class", n + " loop"), s.startCountdown(t, e) }, o) }, i.prototype.fetchSecondsLeft = function (t) { var e = t.data("seconds-left"), n = t.data("minutes-left"); if (Number.isFinite(e)) return parseInt(e, 10); if (Number.isFinite(n)) return 60 * parseFloat(n); throw "Missing time data" }, i.prototype.startCountdown = function (t, e) { e = e || {}; var n = null, o = function () { return clearInterval(n), this.clearTimer(t) }.bind(this); t.onComplete = e.onComplete || o, t.allowPause = e.allowPause || !1, t.allowPause && t.on("click", function () { t.paused ? t.trigger("resume") : t.trigger("pause") }); var s = e.secondsLeft || this.fetchSecondsLeft(t), i = e.refreshRate || 1e3, r = s + this.currentTime(), a = r - this.currentTime(); this.setFinalValue(this.formatTimeLeft(a), t), n = setInterval(function () { (a = r - this.currentTime()) < 0 && (a = 0), t.data("timeLeft", a), this.setFinalValue(this.formatTimeLeft(a), t) }.bind(this), i), t.intervalId = n }, i.prototype.clearTimer = function (t) { t.find(".jst-seconds").text("00"), t.find(".jst-minutes").text("00:"), t.find(".jst-hours").text("00:") }, i.prototype.currentTime = function () { return Math.round((new Date).getTime() / 1e3) }, i.prototype.formatTimeLeft = function (t) { var e = function (t, e) { return (t += "").length >= (e = e || 2) ? t : Array(e - t.length + 1).join(0) + t }, n = Math.floor(t / 3600); t -= 3600 * n; var o = Math.floor(t / 60); t -= 60 * o; var s = parseInt(t % 60, 10); return 0 == +n && 0 == +o && 0 == +s ? [] : [e(n), e(o), e(s)] }, i.prototype.setFinalValue = function (t, e) { if (0 === t.length) return this.clearTimer(e), e.trigger("complete"), !1; e.find("." + this._options.classNameHours).text(t.pop() + ":"), e.find("." + this._options.classNameMinutes).text(t.pop() + ":"), e.find("." + this._options.classNameSeconds).text(t.pop()) }, t.fn.startTimer = function (t) { return this.TimerObject = i, i.start(t, this), this } }); $(function () { $('.timer').startTimer(); }) </script> نقل قول لینک به ارسال
yazdaniwp 1187 ارسال شده در اسفند 99 گزارش بازنشر ارسال شده در اسفند 99 در در ۱۳۹۹/۱۲/۵ در 20:46، hk7887 گفته است : سلام خسته نباشید,یک شمارش معکوس در سایتم دارم که میخوام وقتی به صفر رسید دوباره برگرده و از اول شروع به شمارش کنه یعنی :5,4,3,2,1,0 وقتی به صفر رسید دوباره بر گرده و از 5 بشماره . این کدم هست من خیلی تلاش کردم اما نتونستم همچین چیزی رو پیاده کنم از دوستان کسی بلده کمکم کنه. <div class="container"> <h1> <span class="timer" data-minutes-left="1"></span></h1> </div> <style> span.timer { display: inline-flex; } span.timer { font-size: 15px; margin-right:140px; } div.c-product-box__amazing{ display: flex; flex-direction: column; justify-content: center; height:20px; } </style> <script> ! function (t) { "object" == typeof module && "object" == typeof module.exports ? module.exports = function (e) { t(e, window, document) } : t(jQuery, window, document) }(function (t, e, n, o) { var s; Number.isFinite = Number.isFinite || function (t) { return "number" == typeof t && isFinite(t) }; var i = function (t) { return this._options = {}, this.targetElement = t, this }; i.start = function (t, e) { return function (t, e) { e = e || {}, t._options.elementContainer = e.elementContainer || "div"; var n = e.classNames || {}; t._options.classNameSeconds = n.seconds || "jst-seconds", t._options.classNameMinutes = n.minutes || "jst-minutes", t._options.classNameHours = n.hours || "jst-hours", t._options.classNameClearDiv = n.clearDiv || "jst-clearDiv", t._options.classNameTimeout = n.timeout || "jst-timeout" }(s = new i(e), t), s.start(t) }, i.prototype.start = function (e) { var o = this, i = function (t) { var e = n.createElement(o._options.elementContainer); e.className = o._options.classNameSeconds; var s = n.createElement(o._options.elementContainer); s.className = o._options.classNameMinutes; var i = n.createElement(o._options.elementContainer); i.className = o._options.classNameHours; var r = n.createElement(o._options.elementContainer); return r.className = o._options.classNameClearDiv, t.append(i).append(s).append(e).append(r) }; this.targetElement.each(function (n, o) { var r = this, a = t(o), u = a.attr("class"); return a.on("complete", function () { clearInterval(a.intervalId) }), a.on("complete", function () { a.onComplete(a) }), a.on("complete", function () { a.addClass(r._options.classNameTimeout) }), a.on("complete", function () { e && !0 === e.loop && s.resetTimer(a, e, u) }), a.on("pause", function () { clearInterval(a.intervalId), a.paused = !0 }), a.on("resume", function () { a.paused = !1, r.startCountdown(a, { secondsLeft: a.data("timeLeft") }) }), i(a), this.startCountdown(a, e) }.bind(this)) }, i.prototype.resetTimer = function (t, e, n) { var o = 0; e.loopInterval && (o = 1e3 * parseInt(e.loopInterval, 10)), setTimeout(function () { t.trigger("reset"), t.attr("class", n + " loop"), s.startCountdown(t, e) }, o) }, i.prototype.fetchSecondsLeft = function (t) { var e = t.data("seconds-left"), n = t.data("minutes-left"); if (Number.isFinite(e)) return parseInt(e, 10); if (Number.isFinite(n)) return 60 * parseFloat(n); throw "Missing time data" }, i.prototype.startCountdown = function (t, e) { e = e || {}; var n = null, o = function () { return clearInterval(n), this.clearTimer(t) }.bind(this); t.onComplete = e.onComplete || o, t.allowPause = e.allowPause || !1, t.allowPause && t.on("click", function () { t.paused ? t.trigger("resume") : t.trigger("pause") }); var s = e.secondsLeft || this.fetchSecondsLeft(t), i = e.refreshRate || 1e3, r = s + this.currentTime(), a = r - this.currentTime(); this.setFinalValue(this.formatTimeLeft(a), t), n = setInterval(function () { (a = r - this.currentTime()) < 0 && (a = 0), t.data("timeLeft", a), this.setFinalValue(this.formatTimeLeft(a), t) }.bind(this), i), t.intervalId = n }, i.prototype.clearTimer = function (t) { t.find(".jst-seconds").text("00"), t.find(".jst-minutes").text("00:"), t.find(".jst-hours").text("00:") }, i.prototype.currentTime = function () { return Math.round((new Date).getTime() / 1e3) }, i.prototype.formatTimeLeft = function (t) { var e = function (t, e) { return (t += "").length >= (e = e || 2) ? t : Array(e - t.length + 1).join(0) + t }, n = Math.floor(t / 3600); t -= 3600 * n; var o = Math.floor(t / 60); t -= 60 * o; var s = parseInt(t % 60, 10); return 0 == +n && 0 == +o && 0 == +s ? [] : [e(n), e(o), e(s)] }, i.prototype.setFinalValue = function (t, e) { if (0 === t.length) return this.clearTimer(e), e.trigger("complete"), !1; e.find("." + this._options.classNameHours).text(t.pop() + ":"), e.find("." + this._options.classNameMinutes).text(t.pop() + ":"), e.find("." + this._options.classNameSeconds).text(t.pop()) }, t.fn.startTimer = function (t) { return this.TimerObject = i, i.start(t, this), this } }); $(function () { $('.timer').startTimer(); }) </script> سلام. لطفا در مواقعی که باید کد بررسی بشه، کد رو همین جا درج کنید، نه اینکه پیوست کنید که بشه راحت تر کمک کرد. برای حل این مشکل کافیه که فانکشن آخر رو این مدلی بنویسید: $(function () { $('.timer').startTimer({ loop: true }); }); نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .