简体   繁体   English

如何在 jquery 中隐藏图像并使 label 保持在同一位置?

[英]How can i hide image in jquery and make the label stay at same place?

I am building a game.我正在构建一个游戏。 My character has 5 lives.我的角色有 5 条生命。 When my character gets killed I want to hide 1 life of 5. When I do that with jQuery the label of "Lives:" moves a little bit right (to fill the space formerly occupied by tne life I just hid.当我的角色被杀时,我想隐藏 5 的 1 条生命。当我使用 jQuery 执行此操作时,“生命:”的 label 会向右移动一点(以填充我刚刚隐藏的生命占据的空间。

Example:例子:

在此处输入图像描述

  <div class="items">
    <p class="welcomemsg" id="or">welcome</p>
    <p  style="font-family:Bubble; color:white; font-size:28px; margin-right: 5%;" >Lives:
    <img class="lives" src="./assets/img/logopac.png" alt="pacslogo" id="live1">
    <img class="lives" src="./assets/img/logopac.png" alt="pacslogo" id="live2">
    <img class="lives" src="./assets/img/logopac.png" alt="pacslogo" id="live3">
    <img class="lives" src="./assets/img/logopac.png" alt="pacslogo" id="live4">
  </p>
</div>

  if (board[shape.i][shape.j] == 14) {
    if(livesCounter!=0) {
        $("#live"+livesCounter).hide();
        livesCounter--;
    }
  }

    .items{
        display: flex;
        justify-content: space-between;
        }

    .welcomemsg{
        font-family: 'Bubble';
        font-size: 32px;
        color:white;
        margin-left:5%;
    }

How can I make my label stay in place?如何让我的 label 保持在原位?

Try this:尝试这个:

 .lives { display: inline-block; with: 80 px; }
 <span class="lives"> <img class="live" src="./assets/img/logopac.png" alt="pacslogo" id="live1"> <img class="live" src="./assets/img/logopac.png" alt="pacslogo" id="live1"> <img class="live" src="./assets/img/logopac.png" alt="pacslogo" id="live1"> <img class="live" src="./assets/img/logopac.png" alt="pacslogo" id="live1"> <img class="live" src="./assets/img/logopac.png" alt="pacslogo" id="live1"> </span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将按钮隐藏在图像文本后面,并使它们在所有设备上都位于同一位置? - How to hide buttons behind image text and make them stay in the same place across all devices? 我如何<label>在同一条线上停留</label><form> - How do I make a <label> stay on the same line as it's <form> CSS-使文本在响应图像上停留在同一位置 - CSS - make text stay on same place on responsive image 如何使滑块控件保持在同一位置 - How can i make my slider controls stay at the same position 如何使垂直导航栏的文本在打开时保持在同一位置? - How do I make my vertical navbar's text stay at the same place when it opens? 如何使图像栏保持在手机菜单的最上方? - How can I make an image bar to stay on top with the menu on mobile? 如何使固定的背景图像不能固定在滚动条上? - How can I make a fixed background image not stay fixed on scroll? 放大/缩小时如何使阴影盒保持在同一位置? - how to make a shadowbox stay in the same place when zooming in/out? 如何通过:focus更改属性以使字段停留在同一位置? - How to make field stay in the same place with changing it's attributes with :focus? 悬停时如何使用 CSS 使元素保持原位 - How can I make the element stay in its place with CSS when hovering
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM