Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did it like this (generic counter from N to X (X > N)):</p> <pre><code>var dynamicCounterAddNewValue = 20; var currentDynamicUpdater; function dynamicCounterForValueForControlUpdater(_updaterData) { _updaterData.from += dynamicCounterAddNewValue; if (_updaterData.from &gt; _updaterData.to) { _updaterData.from = _updaterData.to; } _updaterData.c.html(_updaterData.from.toString()); if (_updaterData.from &lt; _updaterData.to) { currentDynamicUpdater = setTimeout( dynamicCounterForValueForControlUpdater, 10, { c: _updaterData.c, from: _updaterData.from, to: _updaterData.to } ); } else { clearTimeout(currentDynamicUpdater); } return; } // _c -&gt; jQuery object (div,span) // _from -&gt; starting number // _to -&gt; ending number function dynamicCounterForValueForControl(_c, _from, _to) { clearTimeout(currentDynamicUpdater); dynamicCounterForValueForControlUpdater( { c: _c, from: _from, to: _to } ); return; } </code></pre> <p>EDIT: <strong>Updated version</strong> (more flexible - <strong>for N elements one after another</strong>):</p> <p>(input element is <em>Array</em> of elements for making them dynamic-counts)</p> <pre><code>var dynamicCounterTimeout = 10; var currentDynamicUpdater; function odcArray(_odca) { this.odca = _odca; return; } function odc(_c, _from, _to) { this.c = _c; // $('#control_id') this.from = _from; // e.g. N this.to = _to; // e.g. M =&gt; (M &gt;= N) var di = parseInt(_to / 45, 10); if (di &lt; 1) { di = 1; } this.dynamicInc = di; return; } function dynamicCounterForValueForControlUpdater(_odca) { if ( _odca.odca === null || !_odca.odca.length ) { clearTimeout(currentDynamicUpdater); return; } var o = _odca.odca[0]; o.from += o.dynamicInc; if (o.from &gt; o.to) { o.from = o.to; _odca.odca.shift(); // Remove first element } o.c.html(o.from.toString()); currentDynamicUpdater = setTimeout( dynamicCounterForValueForControlUpdater, dynamicCounterTimeout, _odca ); return; } function dynamicCounterForValueForControl(_odca) { clearTimeout(currentDynamicUpdater); // SETUP all counters to default for (var i = 0; i &lt; _odca.odca.length; i++) { _odca.odca[i].c.html(_odca.odca[i].from.toString()); } dynamicCounterForValueForControlUpdater( _odca ); return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload