Sunday, October 6, 2024
Google search engine
HomeLanguagesJavascriptFabric.js toHsl() Method

Fabric.js toHsl() Method

The toHsl() method is used to convert any type of the specified color representation to it’s HSL (hue, saturation, and lightness) representation.

Syntax:

toHsl()

Parameters: This method does not accept any parameter.

Return Value: This method returns color representation in HSL format.

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Calling the toHsl() function over 
 // the specified color values
 console.log(new fabric.Color("rgb(10, 120, 150)").toHsl());
 console.log(new fabric.Color("hex(0A7000FF)").toHsl());
</script>
  
</body>
  
</html>


Output:

hsl(193,88%,31%)
hsl(0,0%,0%)

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Initializing some color values in different color format
 var A = "rgb(0, 12, 50)";
 var B = "rgba(10, 13, 250, 0.1)";
 var C = "hex(ff0000)";
  
 // Calling the toHsl() function over 
 // the above specified color values
 console.log(new fabric.Color(A).toHsl());
 console.log(new fabric.Color(B).toHsl());
 console.log(new fabric.Color(C).toHsl());
</script>
  
</body>
  
</html>


Output:

hsl(226,100%,10%)
hsl(239,96%,51%)
hsl(0,0%,0%)

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments