Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js generate color from string

var stringToColour = function(str) {
  var hash = 0;
  for (var i = 0; i < str.length; i++) {
    hash = str.charCodeAt(i) + ((hash << 5) - hash);
  }
  var colour = '#';
  for (var i = 0; i < 3; i++) {
    var value = (hash >> (i * 8)) & 0xFF;
    colour += ('00' + value.toString(16)).substr(-2);
  }
  return colour;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript random alphabet 
Javascript :: event listener for element lost focus 
Javascript :: jquery datatables turn off sorting 
Javascript :: change background color input jquery 
Javascript :: Javascript - check if div contains a word? - Stack Overflow 
Javascript :: sorting disable in datatable bootstrap 
Javascript :: sending form data with fetch using js 
Javascript :: react router Link does work 
Javascript :: console log jquery 
Javascript :: vue htmlWebpackPlugin.options.title 
Javascript :: javascript is variable number or string 
Javascript :: find the last row of table jquery 
Javascript :: how to get utc time in angular 
Javascript :: node load file 
Javascript :: react app.js 
Javascript :: : not foundram Files/nodejs/npm: 3: 
Javascript :: mongoose connection 
Javascript :: javascript remove all child elements 
Javascript :: hide element when pressing button angular 
Javascript :: how to start json server 
Javascript :: react useeffect not on first render 
Javascript :: js remove all objects from array where value 
Javascript :: refresh page after delete angular 
Javascript :: How to show confirm message before delete using jquery 
Javascript :: protractor right click on element 
Javascript :: injected stylesheet remove 
Javascript :: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms node js 
Javascript :: bind and unbind jquery validation 
Javascript :: redirect to another page javascript 
Javascript :: vehicle number yup validation 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =