国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

如何實(shí)現(xiàn)元素背景的隨機(jī)映射?
P粉286046715
P粉286046715 2023-09-11 22:32:31
0
1
669

我想要隨機(jī)設(shè)定每個(gè)元素的背景顏色

但是當(dāng)我將它插入以下程式碼中時(shí),背景顏色變成了透明:

{
  modules.map((module, index) => (
    <div className='carousel-module shadow'
      style={{ background: "#" + Math.floor(Math.random()*16777215).toString(16)}}
    >
      <p className='module-element-text'>{module.name ? module.name : "N/A"}</p>
      <p className='module-element-text'>{module.code ? module.code : "N/A"}</p>
      <Button onClick={() => setShow(false)}
          variant="success" className='modules-list-button'>
          Load
      </Button>
    </div>
  ))
}

很高興聽到您對(duì)如何使其工作的建議。

P粉286046715
P粉286046715

全部回覆(1)
P粉190883225

這是我用來產(chǎn)生十六進(jìn)位顏色的函數(shù)。你的方法可能會(huì)在顏色中引入Alpha通道,使其透明。

function randomHexColor() {
    let toHex = function (n) {
        let hex = n.toString(16);
        while (hex.length < 2) { hex = '0' + hex; }
        return hex;
    };
    let rr = toHex(Math.floor(Math.random() * 256));
    let gg = toHex(Math.floor(Math.random() * 256));
    let bb = toHex(Math.floor(Math.random() * 256));
    return '#' + rr + gg + bb;
}
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板