互联网技术 · 2024年2月16日 0

用JavaScript实现九宫格抽奖

这篇文章主要为大家详细介绍了原生JS九宫格抽奖,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了JS实现九宫格抽奖的具体代码,供大家参考,具体内容如下

上代码:

<div class=”wrapper”>
    <div>谢谢惠顾</div>
    <div>十万元现金</div>
    <div>谢谢惠顾</div>
    <div>iphone11</div>
    <div>抽奖</div>
    <div>美的冰箱</div>
    <div>谢谢惠顾</div>
    <div>50元红包</div>
    <div>谢谢惠顾</div>
  </div>
<div class=”result”></div>

CSS样式代码:

<style>
    .wrapper {
      width: 300px;
      height: 300px;
      display: flex;
      flex-flow: row wrap;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      margin: auto;
      border: 1px solid red;
    }
   
    .wrapper div {
      flex: none;
      width: 100px;
      height: 100px;
      box-sizing: border-box;
      border: 1px solid red;
      display: flex;
      align-items: center;
      justify-content: center;
    }
   
    .active {
      background-color: red;
    }
   
    .wrapper div:nth-child(5) {
      cursor: pointer;
    }
   
    .result {
      height: 100px;
      display: inline-block;
      position: absolute;
      top: 50px;
      left: 0;
      right: 0;
      margin: auto;
      text-align: center;
      line-height: 100px;
      font-size: 40px;
   &nbsp