Jump to content

GreenSock Docs


Returns : Array

Returns an array of RGB (or HSL if the second parameter is true) based on the color values of a given string.

Converts a string-based color value into an array consisting of [red, green, blue] (or if an alpha value is required, it’ll be in the last spot of a 4-element array). It will work with "rgb()", "rgba()", "hsl()", "hsla()", hexidecimal values, or any of the basic named colors.

An example of a returned value would be [255, 128, 0] or [255, 102, 153, 0.5]. Or if you prefer to get HSL-based values, just pass in true as the 2nd parameter.

  1. gsap.utils.splitColor("red"); // [255, 0, 0]
  2. gsap.utils.splitColor("#6fb936"); // [111, 185, 54]
  3. gsap.utils.splitColor("rgba(204, 153, 51, 0.5)"); // [204, 153, 51, 0.5]
  4. // the 2nd parameter indicates we want an HSL value back instead of RGB:
  5. gsap.utils.splitColor("#6fb936", true); // [94, 55, 47]
Copyright 2017, GreenSock. All rights reserved. This work is subject to theterms of useor for Club GreenSock members, the software agreement that was issued with the membership.