vue 1 2 3 4 6 9 16宫格 6宫格(六宫格) 9宫格(九宫格) 16宫格(十六宫格) 自定义宫格(样式篇)

5 篇文章 0 订阅
4 篇文章 0 订阅

直接上图把,如果是你的菜,就点个赞,谢谢。
在这里插入图片描述
目录:
在这里插入图片描述

我直接在app.vue组件写了.。

<template>
  <div class="cell">
        <div class="cell-tool">
            <div class="bk-button-group">
                <button @click="cellCountFn(item.number)" v-for="(item,index) in iconArr" :key="index">{{item.number}}</button>
            </div>
        </div>
        <div class="player">
            <div :class="cellClass(index2)" v-for="(i,index2) in cellCountArr" :key="index2">
                <playVideo :str1="index2+1" ></playVideo>
            </div>
        </div>
    </div>
</template>

<script>
import playVideo from './components/playVideo.vue'

export default {
  name: 'App',
  components: {
    playVideo
  },
  data() {
      return {
        cellCount:4,  //默认从4开始
        cellCountArr: [
          {
            index:1,
            data:null,
            isShow:false
          },
          {
            index:2,
            data:null,
            isShow:false
          },
          {
            index:3,
            data:null,
            isShow:false
          },
          {
            index:4,
            data:null,
            isShow:false
          },
        ],
        iconArr:[             //1 2 3 4 6 9 16宫格 icon 样式
          {
            number:1,   //必须是int(number) 类型 
            name:'el-icon-s-platform',
            tips:'1画面'
          },
          {
            number:2,   //必须是int(number) 类型 
            name:'el-icon-s-platform',
            tips:'2画面'
          },
          {
            number:3,   //必须是int(number) 类型 
            name:'el-icon-s-platform',
            tips:'3画面'
          },
          {
            number:4,   //必须是int(number) 类型 
            name:'el-icon-menu',
            tips:'4画面'
          },
          {
            number:6,   //必须是int(number) 类型 
            name:'el-icon-s-grid',
            tips:'6画面'
          },
          {
            number:8,   //必须是int(number) 类型 
            name:'el-icon-s-grid',
            tips:'8画面'
          },
          {
            number:9,   //必须是int(number) 类型 
            name:'el-icon-s-grid',
            tips:'9画面'
          },
          {
            number:16,  //必须是int(number) 类型 
            name:'el-icon-s-grid',
            tips:'16画面'
          },
          {
            number:0,   //必须是int(number) 类型  根据业务需求
            name:'el-icon-delete',
            tips:'删除所有视频'
          },
        ],  
      }
  },
  methods:{
    // 点击事件
    cellCountFn(number){
      this.cellCount = number
      this.cellCountArr.length = number
    }
  },
  computed: {
    // 计算类样式属性
    cellClass() {
      return function (index) {
        switch (this.cellCount) {
            case 1:
                return ['player-w1']
            case 2:
                return ['player-w2']
            case 3:
              if(index==0)
                  return ['player-w3-1']
                return ['player-w3-2']
            case 4:
                return ['player-w4']
            case 6:
                if (index == 0)
                    return ['player-w6-1']
                return ['player-w6-2']
            case 8:
                if (index == 0)
                    return ['player-w8-1']
                return ['player-w8-2']
            case 9:
                return ['player-9']
            case 16:
                return ['player-16']
            default:
                break;
        }

      }
    },
  },
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

.cell {
  display: flex;
  flex-direction: column;
  height:200px
}
.cell-tool {
  height: 40px;
  line-height: 30px;
  padding: 0 7px;
}
.player {
  height: 200px;
}
.player-w1 {
  width: 100%;
  height:100%;
  box-sizing: border-box;
}
.player-w2 {
  width: 50%;
  height:100%;
  box-sizing: border-box;
  float:left;
}
.player-w3-1 {
  width: 100%;
  height:50%;
  box-sizing: border-box;
  float:left;
}
.player-w3-2 {
  width: 50%;
  height:50%;
  box-sizing: border-box;
  float:left;
}
.player-w4 {
  width: 50%;
  height: 50% !important;
  box-sizing: border-box;/**可有可无 */
  float:left;
}
.player-w6-1 {
  width: 66.66%;
  height: 65.66% !important; /*这里小一点 注意点 */
  box-sizing: border-box;
  float:left;
}
.player-w6-2 {
  width: 33.33%;
  height: 33.33% !important;
  box-sizing: border-box;
  display:inline-table;/**可有可无 */
  float:left;
}
.player-w8-1 {
  width: 75%;
  height: 74% !important;
  box-sizing: border-box;
  float:left;
}
.player-w8-2 {
  width: 25%;
  height: 25% !important;
  box-sizing: border-box;
  display:inline-table; /**可有可无 */
  float:left;
}
.player-9 {
  width: 33.33%;
  height: 33.33% !important;
  box-sizing: border-box;
  float: left;
}
.player-16 {
  width: 25%;
  height: 25% !important;
  box-sizing: border-box;
  float:left;
}
</style>

然后在playVideo.vue组件写播放器的组件。里面其他业务自己实现把。

<template>
  <div class="player">player{{ str1 }}</div>
</template>

<script>
export default {
  name: 'playVideo',
  props: {
      str1: {
          type: String,
          default: ''
      },
  },
  create(){
    console.log("下标",this.str1);
  }
}
</script>

<style scoped>
.player {
    background-color: black;
    height: 100%;
    border: 1px solid white;
    color: white;
    text-align: center;
}
</style>

怕以后第一张图片(效果图)长时间了可能会不见。所以把代码拷贝到项目当中直接实现。也可以运行了。

如果是你的菜,给博主点个赞呗,谢谢。

学到的就要教人 赚到的就要给人。

  • 14
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
实现9宫格抽奖,可以使用Vue.js框架的component组件进行实现。具体步骤如下: 1. 创建一个九宫格的组件,可以通过table标签和tr、td标签组合实现: ``` <template> <table> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> <tr> <td>7</td> <td>8</td> <td>9</td> </tr> </table> </template> ``` 2. 在组件中定义数据,用于控制九宫格指针的指向,以及奖品的位置: ``` <script> export default { data() { return { pointer: 0, // 指针位置 prizeIndex: 4, // 奖品位置 rotating: false // 是否正在旋转 }; } }; </script> ``` 3. 在组件中定义方法,用于处理抽奖逻辑,例如开始抽奖、停止抽奖等: ``` <script> export default { data() { return { pointer: 0, // 指针位置 prizeIndex: 4, // 奖品位置 rotating: false // 是否正在旋转 }; }, methods: { start() { if (this.rotating) return; this.rotating = true; let interval = setInterval(() => { this.pointer = (this.pointer + 1) % 9; }, 100); setTimeout(() => { clearInterval(interval); this.rotating = false; if (this.pointer === this.prizeIndex) { alert("恭喜您中奖了!"); } else { alert("很遗憾,您没有中奖!"); } }, 3000); } } }; </script> ``` 4. 在组件中添加样式,用于实现九宫格样式,以及指针的指向: ``` <style scoped> table { width: 200px; height: 200px; border-collapse: collapse; } td { width: 30px; height: 30px; text-align: center; vertical-align: middle; border: 1px solid #ccc; } .active { background-color: orange; } .pointer { position: relative; &::before, &::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-style: solid; border-width: 0 10px 20px 10px; } &::before { top: -20px; border-color: transparent transparent orange transparent; } &::after { bottom: -20px; border-color: orange transparent transparent transparent; } } </style> ``` 5. 在组件中添加指针的样式类,并根据指针位置动态添加该样式类: ``` <template> <table> <tr> <td :class="{ active: pointer === 0 }">1</td> <td :class="{ active: pointer === 1 }">2</td> <td :class="{ active: pointer === 2 }">3</td> </tr> <tr> <td :class="{ active: pointer === 7 }">4</td> <td :class="{ active: pointer === 8 }">5</td> <td :class="{ active: pointer === 3 }">6</td> </tr> <tr> <td :class="{ active: pointer === 6 }">7</td> <td :class="{ active: pointer === 5 }">8</td> <td :class="{ active: pointer === 4 }">9</td> </tr> </table> </template> ``` 6. 在组件中添加开始抽奖按钮,以及绑定开始抽奖方法: ``` <template> <div> <table> ... </table> <button @click="start">开始抽奖</button> </div> </template> ``` 完整代码如下: ``` <template> <div> <table> <tr> <td :class="{ active: pointer === 0 }">1</td> <td :class="{ active: pointer === 1 }">2</td> <td :class="{ active: pointer === 2 }">3</td> </tr> <tr> <td :class="{ active: pointer === 7 }">4</td> <td :class="{ active: pointer === 8 }">5</td> <td :class="{ active: pointer === 3 }">6</td> </tr> <tr> <td :class="{ active: pointer === 6 }">7</td> <td :class="{ active: pointer === 5 }">8</td> <td :class="{ active: pointer === 4 }">9</td> </tr> </table> <button @click="start">开始抽奖</button> </div> </template> <script> export default { data() { return { pointer: 0, // 指针位置 prizeIndex: 4, // 奖品位置 rotating: false // 是否正在旋转 }; }, methods: { start() { if (this.rotating) return; this.rotating = true; let interval = setInterval(() => { this.pointer = (this.pointer + 1) % 9; }, 100); setTimeout(() => { clearInterval(interval); this.rotating = false; if (this.pointer === this.prizeIndex) { alert("恭喜您中奖了!"); } else { alert("很遗憾,您没有中奖!"); } }, 3000); } } }; </script> <style scoped> table { width: 200px; height: 200px; border-collapse: collapse; } td { width: 30px; height: 30px; text-align: center; vertical-align: middle; border: 1px solid #ccc; } .active { background-color: orange; } .pointer { position: relative; &::before, &::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-style: solid; border-width: 0 10px 20px 10px; } &::before { top: -20px; border-color: transparent transparent orange transparent; } &::after { bottom: -20px; border-color: orange transparent transparent transparent; } } </style> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值