Giter VIP home page Giter VIP logo

Comments (5)

totty90 avatar totty90 commented on May 23, 2024

Use this
function decimalToHex(d) {
var hex = Number(d).toString(16);
hex = "000000".substr(0, 6 - hex.length) + hex;
return hex;
}

from tinycolor.

bgrins avatar bgrins commented on May 23, 2024

I don't understand the issue - a hex character should be 3 or 6 characters. If it cannot be represented with 3 characters then the input should be put into the 6 character notation. From http://www.w3.org/TR/css3-color/#rgb-color:

The format of an RGB value in hexadecimal notation is a ‘#’ immediately followed by either three or six hexadecimal characters. The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros

from tinycolor.

totty90 avatar totty90 commented on May 23, 2024

There are hex that are 4 like in the example in the title. I don't know if is standard or not, but might be used in this lib to accept more input types. Not only hex3 or hex6.
If not, I have to convert all the time with the function..

from tinycolor.

bgrins avatar bgrins commented on May 23, 2024

I try to follow the CSS standard as closely as possible for the accepted string input to prevent any surprises. I've never seen the 4 character hex in any standard, so I'm inclined not to add it. You should be able to wrap the tinycolor function to support this use case using your example code in this issue.

from tinycolor.

totty90 avatar totty90 commented on May 23, 2024

ok, no problem then. I was not using for css but I was using it for a graphical application that uses webgl... I found that lib not limited to css

from tinycolor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.