动画背景颜色就像Angular2中div内的进度条一样

时间:2017-11-29 04:57:55

标签: css angular

我试过在'%'中传递宽度但面临缓慢增加div宽度的问题,如进度条。

这是一个小提琴链接,它是在jQuery中实现的 小提琴链接:http://jsfiddle.net/9wn0vhnn/

我正在尝试在angular2中实现相同的工作实现。

app.component.ts

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

export class AppComponent  {
backgroundColorofdimMix = ['red'];
percentofCurrentPriorMeasure = [50];

 }

app.component.html

<div class='col-xs-12 rmpm' style=' border : 1px solid #ccc;box-shadow: 2px 3px 2px 1px #222;'>

<div style='height:100%;float:left;font-weight:bold;' [ngStyle]="{'background':backgroundColorofdimMix[0],'width':percentofCurrentPriorMeasure[0] + '%','font-size':'12px','padding':'1px','text-align':'center','color':'#000'}">

   AAAAAAA         

</div>

<div style='height:100%;float:left;font-weight:bold;' [ngStyle]="{'line-height':lineHeight,'width': 'calc(100% - '+ percentofCurrentPriorMeasure[0] +'%)','font-size':'12px','padding':'1px','text-align':'center'}">
BBBB
</div>
</div>

1 个答案:

答案 0 :(得分:0)

我在示例Angular 5 App中创建了一个带有自定义进度条CSS的进度条。参考css tricks。检查working demo

TS档案

import { Component } from '@angular/core';
import { Observable } from 'rxjs/Rx';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular 5';
  width : any=0;


  constructor(){
    this.runProgressBar();
  }

  runProgressBar(){
    Observable.timer(0,100)
    .takeWhile(()=>
       this.isWidthWithinLimit()
       )
    .subscribe(()=>{
      this.width=this.width+1;
      console.log(this.width);
    })

  }

  isWidthWithinLimit(){
    if(this.width===100){
      return false;
    }else{
      return true;
    }
  }
}

HTML文件

<div class="meter">
  <span  [style.width]="width+'%'"></span>
</div>

CSS文件

.meter { 
    height: 20px;  /* Can be anything */
    position: relative;
    background: #555;
    -moz-border-radius: 25px;
    -webkit-border-radius: 25px;
    border-radius: 25px;
    padding: 10px;
    box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
}

.meter > span {
  display: block;
  height: 100%;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  border-top-left-radius: 20px;
  border-bottom-left-radius: 20px;
  background-color: rgb(43,194,83);
  background-image: linear-gradient(
    center bottom,
    rgb(43,194,83) 37%,
    rgb(84,240,84) 69%
  );
  box-shadow: 
    inset 0 2px 9px  rgba(255,255,255,0.3),
    inset 0 -2px 6px rgba(0,0,0,0.4);
  position: relative;
  overflow: hidden;
}