0

I am generating unique background color for the contact list, like this

enter image description here
enter image description here

I am trying to generate this like this..

Example

     <ul id="_blocks"></ul>

    <script>
        $(document).ready(function () {
            for (var i = 0; i < 100; i++) {
                $("<li/>").addClass("bts")
                           .append($("<span/>").addClass("_pe_h")
                            .append($("<div/>").addClass("nonDraftPart _pe_o1 _pe_H1")
                           .append(i)))
                            .appendTo($("#_blocks"));
            }
            $('.nonDraftPart').each(function () {
                var hue = 'rgb(' + (Math.floor((256 - 199) * Math.random()) + 200) + ',' + (Math.floor((256 - 199) * Math.random()) + 200) + ',' + (Math.floor((256 - 199) * Math.random()) + 200) + ')';
                $(this).css({ "background-color": hue, "background-size": "cover", "background-position": "50% 50%" });
                console.log(hue);
            });
        });
    </script>

Working Example Js fiddle

Prasad Raja
  • 685
  • 1
  • 9
  • 37

1 Answers1

0

Is requirement to generate pseudo random hexadecimal color codes ?


yeah


function randHex() {
  for (var r = "#"
         // valid hex characters
       , s = "0123456789abcdef"
       ; r.length < 7
       ; r += s.charAt(Math.floor(Math.random() * s.length))
  );
  return r
}

window.onclick = function() {
  console.log(randHex())
}
guest271314
  • 1
  • 15
  • 104
  • 177