Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Strawberry Jellyfish

    (@toxictoad)

    hmmmmmmm…. tricky!

    This might be possible with some cunning CSS nth-child() ::before style selectors to inject the separating character between digit divs. But I think I’d avoid trying that because the current inline styles on digits make that kind of thing a bit of a pain (this is all due to change and become less painful in a future version)

    Or, modify the odometer.js javascript something like this:

    In odometer.js, look for line 136 that begins digitInfo.push(...

    Insert the following code between lines 136 and 137

    // inserting a styled separator character after 1st and 4th digits
            if (i == 0 || i == 3) {
                var separator = document.createElement("div");
                // separator character
                separator.innerHTML = '.'
                // add styles to match digits
                separator.style.cssText = style.digits;
                var separatorDiv = document.createElement("div");
                separatorDiv.style.cssText = style.columns;
                separatorDiv.appendChild(separator);
                // if we are using the 3d highlight effect, add it
                if (!this.disableHighlights) {
                    for (var j in highlights) {
                        var hdiv = document.createElement("div");
                        hdiv.innerHTML="<p></p>";
                        hdiv.style.cssText = highlights[j];
                        separatorDiv.appendChild(hdiv);
                    }
                }
                odometerDiv.appendChild(separatorDiv);
            }

    Now that should give you a ‘.’ after the first and fourth digits of the counter like your example (just change the conditions of the first line to alter positions)

    You’ll also need to alter line 106 from:

    odometerDiv.style.cssText="text-align: left; width:"+(this.digitWidth*this.digits)+"px; height:"+this.digitHeight+"px";

    to:

    odometerDiv.style.cssText="text-align: left; width:"+(this.digitWidth*(this.digits+2))+"px; height:"+this.digitHeight+"px";

    This line just adds extra width to the counter so the new characters fit in, note the (this.digits+2), just change as appropriate if you want more or less separators

    Well that’ll either do exactly what you want or be close enough to get you started. Remember any modifications here will effect all counters and the changes will be lost if you update the plugin when a new version comes out.

    Have fun and shout out if you get stuck!

    Thread Starter jochenc

    (@jochenc)

    Woooow!! Thank you so much for your help!
    I will try this as soon as I find the time (currently working on a other project). I will let you know how everything worked out!

    Thread Starter jochenc

    (@jochenc)

    Worked like a charm! Thanks a lot!

    Plugin Author Strawberry Jellyfish

    (@toxictoad)

    Glad that worked out for you.

    Incidentally, a variation of this feature has made it into the next version of the counter, where you can define a pattern for the counter to include “non counting” parts, such as symbols between digits like you needed, prefixes, postfixes etc.

    Currently under test, to be released.. sometime in the not too distant future. (“Sometime” being dependant on my spare time :D)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘. between digits.’ is closed to new replies.