代码之家  ›  专栏  ›  技术社区  ›  af costa

为每个图像应用固定的像素单位

  •  1
  • af costa  · 技术社区  · 7 年前

    我有一张卡的图片,我需要重复30次,每次我想申请一张特定的卡时,都要左移一个位置,这样它会在停留在一个位置(如牌堆)之前与卡重叠。

    问题是,当我对图像卡应用左位置时,它对所有卡应用相同的左位置,因此没有重叠位置。

    所以我有这样的东西:

    <template>
    <div class=“tripack”>
    <img:style=“‘left':-index*30”v-for=“index in 30”:key=“index”src=“./../assets/images/cardthemes/blue.png”alt=“>
    &L/DIV & GT;
    </template>
    
    脚本& GT;
    导出默认值{
    }
    & /脚本& GT;
    
    <style lang=“scss”>
    TrpACK {
    显示:Flex;
    IMG{
    宽度:80px;
    高度:100px;
    职位:相对;
    }
    }
    &风格/风格;
    < /代码> 
    
    

    I want something like this:

    谢谢你们。

    问题是,当我对图像卡应用左位置时,它对所有卡应用相同的左位置,因此没有重叠位置。

    所以我有这样的东西:

    <template>
      <div class="triPack">
        <img :style="{'left': -index * 30}" v-for="index in 30" :key="index" src="../../assets/images/cardThemes/blue.png" alt="">
      </div>
    </template>
    
    <script>
    export default {
    }
    </script>
    
    <style lang="scss">
      .triPack {
        display: flex;
        img {
          width: 80px;
          height: 100px;
          position: relative;
        }
      }
    </style>
    

    enter image description here

    我想要这样的东西:

    enter image description here

    谢谢大家。

    1 回复  |  直到 7 年前
        1
  •  1
  •   לבני מלכה    7 年前

    你只需要CSS就可以做到 margin-left 除了第一张图片 :not(:first-child)

    所以删除它 :style="{'left': -index * 30}"

    .triPack {
       display: flex;  }
    img {
       width: 80px;
       height: 100px;
        position: relative;
        }
    img:not(:first-child) {
    margin-left: -45px;
    }
     <div class="triPack">
        <img  src="https://i.stack.imgur.com/XG0gL.png" alt="">
        <img  src="https://i.stack.imgur.com/XG0gL.png" alt="">
        <img  src="https://i.stack.imgur.com/XG0gL.png" alt="">
        <img  src="https://i.stack.imgur.com/XG0gL.png" alt="">
        
      </div>