window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/svg\/","svgExt":".svg","source":{"concatemoji":"https:\/\/www.taoxtao.cn\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.4.2"}}; /*! This file is auto-generated */ !function(e,a,t){var r,n,o,i,p=a.createElement("canvas"),s=p.getContext&&p.getContext("2d");function c(e,t){var a=String.fromCharCode;s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,e),0,0);var r=p.toDataURL();return s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,t),0,0),r===p.toDataURL()}function l(e){if(!s||!s.fillText)return!1;switch(s.textBaseline="top",s.font="600 32px Arial",e){case"flag":return!c([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])&&(!c([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!c([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]));case"emoji":return!c([55357,56424,55356,57342,8205,55358,56605,8205,55357,56424,55356,57340],[55357,56424,55356,57342,8203,55358,56605,8203,55357,56424,55356,57340])}return!1}function d(e){var t=a.createElement("script");t.src=e,t.defer=t.type="text/javascript",a.getElementsByTagName("head")[0].appendChild(t)}for(i=Array("flag","emoji"),t.supports={everything:!0,everythingExceptFlag:!0},o=0;o

时间: 2020-08-31|tag: 12次围观|0 条评论

  • 图例

    金额动画组件 – vue+typescript插图
  • 组件代码参考
<template>  <div class="numberCounter">    <h2 :data-to="to" :data-from="from" data-speed="1000" ref="countNumber"></h2>  </div></template><script lang="ts">import { Component, Vue, Prop, Watch } from "vue-property-decorator";@Componentexport default class NumberCounter extends Vue {  @Prop({    type: Number,    default: 0,  })  to!: number;  @Watch("to")  watchTo(val: number) {    $(this.$refs["countNumber"]).attr(      "data-from",      $(this.$refs["countNumber"]).data("to")    );    $(this.$refs["countNumber"]).attr("data-to", val);    this.initialize();    this.start();  }  @Prop({    type: Number,    default: 0,  })  from!: number;  mounted() {    this.initialize();    this.start();  }  initialize() {    ($.fn as any).countTo = function (options: any) {      options = options || {};      return $(this).each(function () {        // 设置当前元素的选项        let settings = $.extend(          {},          ($.fn as any).countTo.defaults,          {            from: +this.dataset.from ? +this.dataset.from : 0,            to: +this.dataset.to ? +this.dataset.to : 0,            speed: $(this).data("speed"),            refreshInterval: $(this).data("refresh-interval"),            decimals: $(this).data("decimals"),          },          options        );        // 多次更新该值,以及每次更新时该值增加多少        let loops = Math.ceil(settings.speed / settings.refreshInterval),          increment = (settings.to - settings.from) / loops;        // 每次更新都会改变的引用和变量        let self = this,          $self = $(this),          loopCount = 0,          value = settings.from,          data = $self.data("countTo") || {};        $self.data("countTo", data);        // 如果可以找到现有的计时器,首先清除它        if (data.interval) {          clearInterval(data.interval);        }        data.interval = setInterval(updateTimer, settings.refreshInterval);        // 用初始值初始化元素        render(value);        function updateTimer() {          value += increment;          loopCount++;          render(value);          if (typeof settings.onUpdate == "function") {            settings.onUpdate.call(self, value);          }          if (loopCount >= loops) {            // 删除间隔            $self.removeData("countTo");            clearInterval(data.interval);            value = settings.to;            if (typeof settings.onComplete == "function") {              settings.onComplete.call(self, value);            }          }        }        function render(value: any) {          let formattedValue = settings.formatter.call(self, value, settings);          formattedValue = formattedValue === "-0.00" ? "0.00" : formattedValue;          $self.html(formattedValue);        }      });    };    // 初始化默认值    ($.fn as any).countTo.defaults = {      from: 0, // 元素的起始数字      to: 0, // 元素结束的数字      speed: 1000, // 需要多长时间来计算目标数字      refreshInterval: 100, // 元素应该多久更新一次      decimals: 2, // 要表示的小数位数      formatter: formatter, // 处理程序,用于在呈现之前格式化值      onUpdate: null, // 每次更新元素时的回调方法      onComplete: null, // 元素完成更新时的回调方法    };    function formatter(value: any, settings: any) {      return value.toFixed(settings.decimals);    }    // 自定义格式示例    $(this.$refs.countNumber).data("countToOptions", {      formatter: function (value: any, options: any) {        return value          .toFixed(options.decimals)          .replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");      },    });  }  start() {    // 启动所有计时器    $(this.$refs.countNumber).each(count);    function count(this: any, options: any) {      let $this: any = $(this);      options = $.extend({}, options || {}, $this.data("countToOptions") || {});      $this.countTo(options);    }  }}</script><style scoped lang="scss">.numberCounter {}</style>
  • 使用
<div class="orderBoxInner" @click="lendingQuotas.number=100901">  <number-counter :to="lendingQuotas.number" />  <h3 class="orderDocs">放款额度(元)</h3></div>

文章转载于:https://www.jianshu.com/p/7df0731d694c

原著是一个有趣的人,若有侵权,请通知删除

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《金额动画组件 – vue+typescript
   

还没有人抢沙发呢~