Обратный остчет
есть вот такой скрипт
define("countdown",[],function(){var e={start:20,storage:!0,init:function(){var t,r,n,i;this.$el=$(".countdown"),this.$descr=$(".countdown-descr"),this.placesTotal=$(".places-total"),this.$place1=$(".place-1"),this.$place2=$(".place-2"),this.$place3=$(".place-3");try{localStorage.setItem("item","text"),localStorage.removeItem("item")}catch(a){e.storage=!1}localStorage.countdownValue&&localStorage.countdownDate?(this.value=localStorage.countdownValue,this.$el.html(this.value),n=new Date(localStorage.countdownDate),r=new Date,i=Math.round(Math.abs((r.getTime()-n.getTime())/864e5)),i>0&&this.value>3&&(i+1>this.value&&(i=1),this.value-=i,this.save()),localStorage.setItem("countdownDate",new Date)):(this.value=this.start,this.save()),this.value>20&&(t=setInterval(function(){e.value>20?(e.value--,localStorage.setItem("countdownDate",new Date),e.save()):clearInterval(t)},200)),this.saveDescr()},save:function(){localStorage.setItem("countdownValue",this.value),this.$el.html(this.value),this.value===this.start?this.placesTotal.hide():this.placesTotal.show()},reducePlaces:function(){for(var e,t=this.$place1.html(),r=this.$place2.html(),n=this.$place3.html(),i=!1;0==i;)if(e=Math.round(3*Math.random()+1),1==e){if(3>t)continue;this.$place1.html(--t),i=!0}else if(3==e){if(3>n)continue;this.$place3.html(--n),i=!0}else if(3==e||4==e){if(3>r)continue;this.$place2.html(--r),i=!0}},saveDescr:function(){this.value<3&&this.$descr.html("места")}};return e}) что мне нужно изменить чтоб отсчет был по три каждый день от 20ти. сейчас почему то отсчет по 1 в день... |
Что означает
Цитата:
|
есть некое число 20 (количество пряников). Нужно чтобы каждый день от него отнималось 3(пряника). Когда приников нестанет, нужно чтобы цикл повторился, сейчас отнимается по одному каждый день. Я в javascript плохо очень разбираюсь, поэтому трудно самому догадаться что да как в этом скрипте.
|
Yaroslav222333,
пробуйте, может получится <script> define("countdown", [], function () { var e = { start: 20, storage: !0, init: function () { var t, r, n, i; this.$el = $(".countdown"), this.$descr = $(".countdown-descr"), this.placesTotal = $(".places-total"), this.$place1 = $(".place-1"), this.$place2 = $(".place-2"), this.$place3 = $(".place-3"); try { localStorage.setItem("item", "text"), localStorage.removeItem("item") } catch (a) { e.storage = !1 } localStorage.countdownValue && localStorage.countdownDate ? (this.value = localStorage.countdownValue, this.$el.html(this.value), n = new Date(localStorage.countdownDate), r = new Date, i = Math.round(Math.abs((r.getTime() - n.getTime()) / 864e5)), i > 0 && this.value > 3 && (i + 1 > this.value && (i = 1), this.value -= i+2, this.save()), localStorage.setItem("countdownDate", new Date)) : (this.value = this.start, this.save()), this.value > 20 && (t = setInterval(function () { e.value > 20 ? (e.value = e.value - 3, localStorage.setItem("countdownDate", new Date), e.save()) : clearInterval(t) }, 200)), this.saveDescr() }, save: function () { localStorage.setItem("countdownValue", this.value), this.$el.html(this.value), this.value === this.start ? this.placesTotal.hide() : this.placesTotal.show() }, reducePlaces: function () { for (var e, t = this.$place1.html(), r = this.$place2.html(), n = this.$place3.html(), i = !1; 0 == i;)if (e = Math.round(3 * Math.random() + 1), 1 == e) { if (3 > t)continue; this.$place1.html(--t), i = !0 } else if (3 == e) { if (3 > n)continue; this.$place3.html(--n), i = !0 } else if (3 == e || 4 == e) { if (3 > r)continue; this.$place2.html(--r), i = !0 } }, saveDescr: function () { this.value < 3 && this.$descr.html("места") } }; return e }) </script> |
в общем, поставил, но так и не заработало, -1 пряник каждый день... посоветовали вот такое решение
define("countdown", [], function () { var Countdown = { start: 17, storage: true, init: function () { var interval, now, then, diff, random, placeValue; this.$el = $(".countdown"); this.$descr = $(".countdown-descr"); this.placesTotal = $(".places-total"); this.$place1 = $(".place-1"); this.$place2 = $(".place-2"); this.$place3 = $(".place-3"); try { localStorage.setItem("item", "text"); localStorage.removeItem("item"); } catch (e) { Countdown.storage = false; } if (localStorage.countdownValue && localStorage.countdownDate) { this.value = localStorage.countdownValue; this.$el.html(this.value); then = new Date(localStorage.countdownDate); now = new Date(); diff = Math.round(Math.abs((now.getTime() - then.getTime()) / 8.64e7 )); if (diff > 0 && this.value > 3) { if (diff + 1 > this.value) { diff = 1; } this.value -= diff; this.save(); } localStorage.setItem("countdownDate", new Date()); } else { this.value = this.start; this.save(); } if (this.value > 17) { interval = setInterval(function () { if (Countdown.value > 17) { Countdown.value--; localStorage.setItem("countdownDate", new Date()); Countdown.save(); } else { clearInterval(interval); } }, 200); } this.saveDescr(); }, save: function () { localStorage.setItem("countdownValue", this.value); this.$el.html(this.value); if (this.value === this.start) { this.placesTotal.hide(); } else { this.placesTotal.show(); } }, reducePlaces: function () { var value1 = this.$place1.html(), value2 = this.$place2.html(), value3 = this.$place3.html(), random, success = false; while (success == false) { random = Math.round(Math.random() * (4 - 1) + 1); if (random == 1) { if (value1 < 3) { continue; } else { this.$place1.html(-3); //--value success = true; } } else if (random == 3) { if (value3 < 3) { continue; } else { this.$place3.html(--value3); success = true; } } else if (random == 3 || random == 4) { if (value2 < 3) { continue; } else { this.$place2.html(--value2); success = true; } } } }, saveDescr: function () { if (this.value < 5) { this.$descr.html("места"); } } } return Countdown; }) но эфект все тот же... -1, я уже не знаю к кому обращаться и что писать... |
Часовой пояс GMT +3, время: 07:57. |