The css method will output a valid W3C string (without vendors prefix) to use with background-image CSS property.
// linear gradient to right (default)const gradientStr = gradient.css();// radial gradient ellipse at top leftconst gradientStr = gradient.css('radial', 'farthest-corner ellipse at top left');
Get color at a specific position
Returns a single TinyColor object from a defined position in the gradient (from 0 to 1).
// with RGB interpolationcolorAt55Percent = gradient.rgbAt(0.55);// with HSV interpolationcolorAt55Percent = gradient.hsvAt(0.55);
Reversing gradient
Returns a new instance of TinyGradient with reversed colors.
const reversedGradient = gradient.reverse();
Loop the gradient
Returns a new instance of TinyGradient with looped colors.
const loopedGradient = gradient.loop();
Position-only stops
I is possible to define stops with the pos property only and no color. This allows to define the position of the mid-point between the previous and the next stop.
const gradient = tinygradient([ {color: 'black', pos: 0}, {pos: 0.8}, // #808080 will be at 80% instead of 50% {color: 'white', pos: 1}]);