我在json文件中有数据.我从这个json生成了一个progressbar.

enter image description here

json文件:

  jsonArray = [
    {
      text: 'Show this first',
      gradue: 92,
    },
    {
      text: 'Then show this after some millisconds',
      gradue: 88,
    },
    {
      text: 'Show this at least after some more milliseconds',
      gradue: 81,
    }
  ];

css代码如下,以使progressbar加载从0%到92%

.percentage {
  color: #522003;
  font-size: 10px;
  font-weight: bold;
  margin-right: 0.6rem;
  line-height: 9px;
  text-align: end;
}

@property --p {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

.skill-progress-fill {
  --p: 20;

  background: linear-gradient(to right, #e15d10, #f07d3b);
  height: 100%;
  border-radius: inherit;
  animation: animation 4s cubic-bezier(0.28, 1.07, 0.24, 1.01);
  width: calc(var(--p) * 1%);
}

@keyframes animation {
  0% {
    width: 0%;
  }
  100% {
    width: calc(var(--p) * 1%);
  }
}

Anguar HTML文件:

<div class="skill-progress-fill" style="--p:{{ percent }}"><span class="percentage">{{ percent }}%</span></div>

有人能帮我解决这个问题吗.顺便说一句,我不是在寻找 bootstrap 解决方案.

推荐答案

我找到了Angular 动画模块.这是ne的解决方案.

Content

1)创建可广泛共享的新typescript文件->;app.animations.ts

2)将BrowserAnimationsModule导入模块->;app.modules.ts

3)在中导入和定义动画->;应用程序组件.ts(或要使用动画的组件)

4)将动画应用于html->;应用程序组件.例如html.

Let's Start

1)以较慢的动画速度(300ms)创建一个新的typescript文件,以便查看动画.

import {
  trigger,
  transition,
  style,
  animate,
  query,
  stagger,
} from '@angular/animations';

export const listAnimation = trigger('listAnimation', [
  transition('* <=> *', [
    query(
      ':enter',
      [
        style({ opacity: 0 }),
        stagger('300ms', animate('3000ms ease-out', style({ opacity: 1 }))),
      ],
      { optional: true }
    ),
    query(':leave', animate('300ms', style({ opacity: 0 })), {
      optional: true,
    }),
  ]),
]);

2.)导入Angular 动画

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  imports: [
    BrowserAnimationsModule
   }),
  ]
})

3.)在组件中导入和定义动画

import { listAnimation } from './app.animations';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  animations: [listAnimation],
})

4)将动画应用于组件html数组列表->;app.component.html

    <ul [@listAnimation]="jsonArray.length">
        <li *ngFor="let element of jsonArray">{{element}}</li>
    </ul>

Finally see the result

注意目标只是,从上到下的行将显示延时.progressbar中从左到右的动画是另一种解决方案(纯css)

enter image description here

Javascript相关问答推荐

订阅操作顺序

获取表格的左滚动位置

JS生成具有给定数字和幻灯片计数的数组子集

RxJS setTimeout操作符等效

可以的.是否可以在不预编译的情况下使用嵌套 Select 器?

使用json文件字符串来enum显示类型字符串无法按照计算的enum成员值的要求分配给类型号

从PWA中的内部存储读取文件

在我的html表单中的用户输入没有被传送到我的google表单中

简单的PayPal按钮集成导致404错误

如何从网站www.example.com获取表与Cheerio谷歌应用程序脚本

如何使用JavaScript拆分带空格的单词

如何在ASP.NET项目中使用Google Chart API JavaScript将二次轴线值格式化为百分比

以Angular 实现ng-Circle-Progress时出错:模块没有导出的成员

为什么延迟在我的laravel项目中不起作用?

使用RxJS from Event和@ViewChild vs KeyUp事件和RxJS主题更改输入字段值

如何修复使用axios运行TSC index.ts时出现的错误?

react 路由如何使用从加载器返回的数据

我怎样才能点击一个元素,并获得一个与 puppeteer 师导航页面的URL?

如何在移动设备中使用JAVASSCRIPT移除点击时的焦点/悬停状态

重新渲染过多(&Q).REACT限制渲染次数以防止无限循环.使用REACT下拉菜单时