Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

html - Animate image to move to the right to a specific position in Angular

I'm doing a web application in Angular 11. We have an image that is a table with 4 columns and a simple icon below it. We would like to move the icon to the right based on a value (number) that I receives from the backend (HTTP call).

Image (690x450):

H1 H2 H3 H4
1 2 3 4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the CSS variables.

#slide {
  position: absolute;
  width: 100px;
  height: 100px;
  -webkit-animation: slide 0.5s forwards;
  -webkit-animation-delay: 0.5s;
  animation: slide 0.5s forwards;
  animation-delay: 2s;
}

@-webkit-keyframes slide {
  100% { var(--left); }
}

@keyframes slide {
  100% { var(--left); }
}

And pass it via the HTML

 <div class="row justify-content-center">
    <div class="col-auto">
      <div class="band-container">
        <table class="table table-borderless">
          <tbody>
          <tr>
            <td class="p-0">
              <img src="assets/imgs/table.png" width="590" height="350"/>
            </td>
          </tr>
          <tr *ngIf="(number$ | async) as number">
            <td class="p-0">
              <img id="slide" style="--left: distance;" src="assets/icons/hand.png" />
            </td>
          </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>

Here's an example https://jsfiddle.net/204aubw6/

It doesn't have full support for all browsers, but since you are doing Angular 11, IE won't matter anyway https://caniuse.com/css-variables.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...