Note that there are some explanatory texts on larger screens.

plurals
  1. POEditing jquery-countdown to fit my HTML element
    primarykey
    data
    text
    <p>I've collected a nice jQuery countdown script from <a href="https://github.com/Reflejo/jquery-countdown" rel="nofollow noreferrer">here</a>. It needs no configuration but a great opensource project. But where I want to set is a smaller place like 50%. So, now I want to make it 50% on both width and height. First of all I opened <code>digits.png</code> with photoshop and made it 50%, then I opened <code>jquery.countdown.js</code> and the code is following:</p> <pre><code>jQuery.fn.countdown = function(userOptions) { // Default options var options = { stepTime: 60, // startTime and format MUST follow the same format. // also you cannot specify a format unordered (e.g. hh:ss:mm is wrong) format: "dd:hh:mm:ss", startTime: "01:12:32:55", digitImages: 6, digitWidth: 67, digitHeight: 90, timerEnd: function(){}, image: "digits.png", continuous: false }; var digits = [], intervals = []; // Draw digits in given container var createDigits = function(where) { var c = 0; // Iterate each startTime digit, if it is not a digit // we'll asume that it's a separator for (var i = 0; i &lt; options.startTime.length; i++) { if (parseInt(options.startTime[i]) &gt;= 0) { elem = $('&lt;div id="cnt_' + c + '" class="cntDigit" /&gt;').css({ height: options.digitHeight, float: 'left', background: 'url(\'' + options.image + '\')', width: options.digitWidth }); elem.current = parseInt(options.startTime[i]); digits.push(elem); margin(c, -elem.current * options.digitHeight * options.digitImages); if (options.continuous === true) { digits[c]._max = function(){ return 9; }; } else { // Add max digits, for example, first digit of minutes (mm) has // a max of 5. Conditional max is used when the left digit has reach // the max. For example second "hours" digit has a conditional max of 4 switch (options.format[i]) { case 'h': digits[c]._max = function(pos, isStart) { if (pos % 2 == 0) return 2; else return (isStart) ? 3: 9; }; break; case 'd': digits[c]._max = function(){ return 9; }; break; case 'm': case 's': digits[c]._max = function(pos){ return (pos % 2 == 0) ? 5: 9; }; } } ++c; } else { elem = $('&lt;div class="cntSeparator"/&gt;').css({float: 'left'}) .text(options.startTime[i]); } where.append(elem) } }; // Set or get element margin var margin = function(elem, val) { if (val !== undefined) { digits[elem].margin = val; return digits[elem].css({'backgroundPosition': '0 ' + val + 'px'}); } return digits[elem].margin || 0; }; var makeMovement = function(elem, steps, isForward) { // Stop any other movement over the same digit. if (intervals[elem]) window.clearInterval(intervals[elem]); // Move to the initial position (We force that because in chrome // there are some scenarios where digits lost sync) var initialPos = -(options.digitHeight * options.digitImages * digits[elem].current); margin(elem, initialPos); digits[elem].current = digits[elem].current + ((isForward) ? steps: -steps); var x = 0; intervals[elem] = setInterval(function(){ if (x++ === options.digitImages * steps) { window.clearInterval(intervals[elem]); delete intervals[elem]; return; } var diff = isForward ? -options.digitHeight: options.digitHeight; margin(elem, initialPos + (x * diff)); }, options.stepTime / steps); }; // Makes the movement. This is done by "digitImages" steps. var moveDigit = function(elem) { if (digits[elem].current == 0) { // Is there still time left? if (elem &gt; 0) { var isStart = (digits[elem - 1].current == 0); makeMovement(elem, digits[elem]._max(elem, isStart), true); moveDigit(elem - 1); } else // That condition means that we reach the end! 00:00. { for (var i = 0; i &lt; digits.length; i++) { clearInterval(intervals[i]); clearInterval(intervals.main); margin(i, 0); } options.timerEnd(); } return; } makeMovement(elem, 1); }; $.extend(options, userOptions); createDigits(this); intervals.main = setInterval(function(){ moveDigit(digits.length - 1); }, 1000); }; </code></pre> <p>I tried changing some variables, <code>digitWidth: 67</code> to <code>digitWidth: 34</code> then <code>digitHeight: 90</code> to <code>digitHeight: 45</code> with no success. I want to make the countdown timer just half than the original. Can you suggest any change anywhere in the code, please?</p> <p><strong>Update:</strong> This is <a href="https://i.stack.imgur.com/e5E87.png" rel="nofollow noreferrer"><code>digits.png</code></a>, 50% than original!</p> <p>I also changed associated div's like <code>#holder</code> with no success.</p> <p>Following is the current situation of the timer. The red marked places are the problems I mean misplaced. <img src="https://i.stack.imgur.com/XLMzn.png" alt="This"></p>
    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.
 

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