实现5*5正方形网格x轴和y轴显示对应数值组件封装

这篇具有很好参考价值的文章主要介绍了实现5*5正方形网格x轴和y轴显示对应数值组件封装。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

实现5*5正方形网格x轴和y轴显示对应数值组件封装

需求:按5*5的正方形网格,根据目标数据的x和y轴值显示对应的文字,实现效果图如下:(当前目标数值:x=2,y=2)

实现5*5正方形网格x轴和y轴显示对应数值组件封装,css3,css,javascript,vue.js文章来源地址https://www.toymoban.com/news/detail-627657.html

代码如下:

<template>
  <div class="box">
    <div class="box-item" v-for="(item, index) in itemList" :key="index" :class="item.className">
      {{ (x === item.x && y === item.y) ? item.label : '' }}
    </div>
  </div>
</template>

<script setup lang="ts">
withDefaults(defineProps<{
  x?: number,
  y?: number
}>(), {
  x: 2,
  y: 2
})

interface itemType {
  className: string;
  label: string;
  x: number;
  y: number;
}
let itemList: itemType[] = Array.from({ length: 25 }).map((_, index) => {
  let result = {
    className: '',
    label: '中',
    x: 0,
    y: 0
  }
  if ([3, 4, 8, 9, 14].includes(index)) {
    result.className = 'blue'
    result.label = '高'
  } else if ([10, 15, 16, 20, 21].includes(index)) {
    result.className = 'orange'
    result.label = '低'
  }
  result.className += ` xy-${index}`
  return result
})
let Y = 10
for (let j = 0; j < 25; j += 5) {
  for (let i = j; i < j + 5; i++) {
    if ([0, 5, 10, 15, 20].includes(i)) {
      itemList[i].x = 2
    } else {
      itemList[i].x = itemList[i - 1].x + 2
    }
    itemList[i].y = Y
  }
  Y -= 2
}
</script>

<style lang="scss" scoped>
.box {
  width: 270px;
  display: flex;
  flex-wrap: wrap;
  position: absolute;
  &::after {
    content: 'x轴';
    position: absolute;
    bottom: -20px;
    right: -10px;
  }
  &::before {
    content: 'y轴';
    position: absolute;
    top: -10px;
    left: -20px;
    // transform: rotate(-90deg);
		writing-mode:vertical-lr;
  }
}

.box-item {
  width: 20%;
  height: 50px;
  border: 1px solid #ff0000;
  box-sizing: border-box;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  &.xy-0::after {
    content: '10';
    position: absolute;
    left: -20px;
  }
  &.xy-5::after {
    content: '8';
    position: absolute;
    left: -20px;
  }
  &.xy-10::after {
    content: '6';
    position: absolute;
    left: -20px;
  }
  &.xy-15::after {
    content: '4';
    position: absolute;
    left: -20px;
  }
  &.xy-20::after {
    content: '2';
    position: absolute;
    left: -20px;
  }
  &.xy-20::before {
    content: '2';
    position: absolute;
    bottom: -20px;
  }
  &.xy-21::before {
    content: '4';
    position: absolute;
    bottom: -20px;
  }
  &.xy-22::before {
    content: '6';
    position: absolute;
    bottom: -20px;
  }
  &.xy-23::before {
    content: '8';
    position: absolute;
    bottom: -20px;
  }
  &.xy-24::before {
    content: '10';
    position: absolute;
    bottom: -20px;
  }
}

.blue {
  background-color: skyblue;
}

.orange {
  background-color: orange;
}
</style>

到了这里,关于实现5*5正方形网格x轴和y轴显示对应数值组件封装的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Python-彩色正方形

    核心代码 核心代码 核心代码

    2024年02月19日
    浏览(30)
  • CSS 3D旋转正方形

    2024年01月23日
    浏览(31)
  • LeetCode-221. 最大正方形

    题目来源 221. 最大正方形 现在我们需要找到只包含 ‘1’ 的最大正方形。首先,我们可以初始化一个和原始矩阵相同大小的矩阵 dp,用来记录每个格子所在的最大正方形的边长。 对于第一行和第一列的格子,它们的 dp 值只能是 0 或 1,因为它们的左侧或上侧没有格子。我们

    2023年04月11日
    浏览(34)
  • python绘制螺旋正方形

    1.首先导入画图功能库turtle 2.设置画笔大小,颜色  turtle.pensize()  turtle.pencolor() 3.如何绘制:螺旋正方形一开始外边有3条长度相同的边,先勾勒出一条边循环3次将外边构出,里边每勾勒一条循环两次,再进行循环,即需要一个双循环,边每次比前一次缩短。 画笔前进  turt

    2024年04月15日
    浏览(35)
  • 力扣221.最大正方形(动态规划)

    思路: 思路:从[0,0]元素开始,计算每个元素对应其与[0,0]之间矩阵块中最大正方形边长 情况:1)matrix [ i , j ] = ‘0’ -- 元素对应的最大正方形为0。 情况:2)matrix [ i , j ] = ‘1’ -- max ( matrix [ i-1 , j ] , matrix [ i - 1 , j - 1 ) ,matrix [ i , j - 1 ] ) + 1 具体实现:1)先找出第一行和第

    2024年02月13日
    浏览(28)
  • P1387 最大正方形 题解

    通过二维前缀和判定矩形内是否全为1,计算和等于长度的平方就判断为是 复杂度 (Theta (n^2log{n})) 设状态 (f_{i,j}) 为以第 (i) 行 (j) 列为右下角的最大正方形的边长, (a_{i,j}) 表示输入矩阵中的数值,有转移方程: [f_{i,j} = (min(f_{i-1,j},f_{i,j-1},f_{i-1,j-1}) + 1) * a_{i,j}] 解释:

    2024年02月16日
    浏览(31)
  • 洛谷 P1387 最大正方形 题解

    通过二维前缀和判定矩形内是否全为1,计算和等于长度的平方就判断为是 复杂度 (Theta (n^2log{n})) 设状态 (f_{i,j}) 为以第 (i) 行 (j) 列为右下角的最大正方形的边长, (a_{i,j}) 表示输入矩阵中的数值,有转移方程: [f_{i,j} = (min(f_{i-1,j},f_{i,j-1},f_{i-1,j-1}) + 1) * a_{i,j}] 解释:

    2024年02月16日
    浏览(35)
  • 【LeetCode-中等】221. 最大正方形(详解)

    在一个由  \\\'0\\\'  和  \\\'1\\\'  组成的二维矩阵内,找到只包含  \\\'1\\\'  的最大正方形,并返回其面积。 力扣原题链接   暴力法一般不是最优解,但是可以拿来练手 由于正方形的面积等于边长的平方,因此要找到最大正方形的面积,首先需要找到最大正方形的边长,然后计算最大边

    2024年02月13日
    浏览(41)
  • 将正方形矩阵顺时针转动 90°

    【题目】 给定一个 N×N 的矩阵 matrix,把这个矩阵调整成顺时针转动 90°后的形式。 例如: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 顺时针转动 90°后为: 13 9 5 1 14 10 6 2 15 11 7 3 16 12 8 4 【要求】 额外空间复杂度为 O(1)。 思路: 这里使用分圈处理的方式,在矩阵中用左上角的坐标(tR,tC)和

    2024年02月13日
    浏览(28)
  • 最大正方形(力扣)暴力 + 动态规划 JAVA

    在一个由 ‘0’ 和 ‘1’ 组成的二维矩阵内,找到只包含 ‘1’ 的最大正方形,并返回其面积。 示例 1: 输入:matrix = [[“1”,“0”,“1”,“0”,“0”],[“1”,“0”,“1”,“1”,“1”],[“1”,“1”,“1”,“1”,“1”],[“1”,“0”,“0”,“1”,“0”]] 输出:4 示例 2: 输入:m

    2024年02月15日
    浏览(54)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包