Skip to content

Add a color option on revealer#7

Open
Atala wants to merge 2 commits into
dulacp:masterfrom
Atala:color-option
Open

Add a color option on revealer#7
Atala wants to merge 2 commits into
dulacp:masterfrom
Atala:color-option

Conversation

@Atala

@Atala Atala commented Jun 29, 2014

Copy link
Copy Markdown
Contributor

Feedback appreciated #newbie

Atala added 2 commits June 29, 2014 15:22
Conflicts:
	examples/assets/jquery.revealing.js
	src/revealing.js
@Atala Atala changed the title Add a color option on picker Add a color option on revealer Jun 29, 2014
@dulacp

dulacp commented Jun 20, 2015

Copy link
Copy Markdown
Owner

Hey, this one is a little bit too specific. Because in a real use case scenario you'll use css to specify the color you want, even specify a different color for each letter !

Maybe that's what this PR need more, an example showing how to specify a differ color for each letter, don't you think ?

Cheers man

@Atala

Atala commented Jun 21, 2015

Copy link
Copy Markdown
Contributor Author

Looking at the diff, the color picker seems a bit overkill.

Actually you would use a custom tokenizer and insert around each letter no?

I add to solve a related problem recently, a 5 digits counter, starting from one, with leading 0 with less opacity.

function getDisplay() {
    var counterLength = 5,
        numItem = getCount(),
        prefix = '<span class="book-banner-header-leading">' + Array(counterLength + 1 - numItem.toString().length).join('0') + '</span>';
    return prefix + numItem.toString();
}

@dulacp

dulacp commented Jun 22, 2015

Copy link
Copy Markdown
Owner

Hey! interesting problem for your 5 digits, actually I would have used css to solve this issue. In addition you'll get nice animations out of the box by using css styles.

I've tried this approach in a little jsfiddle demo.

For the posterity I've attached the core concept code :

html

<div class="counter" data-count=0 data-digit-length=5>
    <span>0</span>
    <span>0</span>
    <span>0</span>
    <span>0</span>
    <span>0</span>
</div>
<div class="btn-group">
    <button id="down">-1</button>
    <button id="up">+1</button>
</div>

css

span {
    display: inline-block;
    opacity: 0.15;
    transition: opacity 800ms ease-out;
}
.counter[data-digits="1"] span:nth-child(n+5), .counter[data-digits="2"] span:nth-child(n+4), .counter[data-digits="3"] span:nth-child(n+3), .counter[data-digits="4"] span:nth-child(n+2), .counter[data-digits="5"] span:nth-child(n+1) {
    opacity: 1.0;
}

js

var counter = document.querySelector('.counter');

function updateDisplay(count) {
    var digits = count.toString().split('');
    counter.dataset.digits = digits.length;

    // reset to 0 every value
    Array.prototype.forEach.call(counter.querySelectorAll('span'), function(s) {
        s.innerHTML = '0'; 
    });

    // fill the digits
    var dl = counter.dataset.digitLength;
    digits.forEach(function(d, idx) { 
        counter.querySelector('span:nth-child('+(dl - digits.length + idx + 1)+')').innerHTML = d;
    });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants