randomColor.js 358 B

12345678910111213141516
  1. /**
  2. *
  3. * @desc 随机生成颜色
  4. * @return {String}
  5. */
  6. // 第一种方法:
  7. function randomColor() {
  8. return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
  9. };
  10. // 第二种方法:
  11. // function randomColor() {
  12. // return '#' + Math.random().toString(16).substring(2).substr(0, 6);
  13. // };
  14. module.exports = randomColor;