Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xiaohe-vue-count-to

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xiaohe-vue-count-to

⏱️ 一个实现数字平滑变化的Vue小组件

  • 0.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-44.44%
Maintainers
1
Weekly downloads
 
Created
Source

xiaohe-vue-count-to

⏱️ 一个实现数字平滑变化的Vue小组件

github stars npm version npm downloads bundle JSDocs License

小何同学 / github@xiaohe0601 / gitee@xiaohe0601

🎉 特性

  • 🍜 支持非线性动画
  • 🍟 支持中途打断动画
  • 🐼 支持Vue 2/3
  • 🧀 支持TypeScript
  • 🍳 支持免费商用
  • 🥗 更多特性等你发掘...

🎮 示例

xiaohe-vue-count-to

还可以试一试在线DEMO

🚁 安装

PNPM
pnpm add xiaohe-vue-count-to
YARN
yarn add xiaohe-vue-count-to
NPM
npm install xiaohe-vue-count-to
另外

如果 Vue 版本小于 2.7,还需要安装 @vue/composition-api

pnpm add @vue/composition-api

🛹 使用

简单使用
<template>
  <count-to :value="pandora">
    <template #default="{ value }">
      <span>{{ value }}</span>
    </template>
  </count-to>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { CountTo } from "xiaohe-vue-count-to";

const pandora = ref<number>(0);

onMounted(() => {
  setTimeout(() => {
    pandora.value = 20000;
  }, 100);
});
</script>
控制动画
  • Vue 3 可直接通过 ref 获取到 xiaohe-transition 实例用于控制动画

    <template>
      <count-to ref="counter" :value="pandora">
        <template #default="{ value }">
          <span>{{ value }}</span>
        </template>
      </count-to>
    </template>
    
    <script lang="ts" setup>
    import { ref } from "vue";
    import type { CountToInst } from "xiaohe-vue-count-to";
    import { CountTo } from "xiaohe-vue-count-to";
    
    const counter = ref<CountToInst | null>(null);
    
    const pandora = ref<number>(0);
    
    /**
     * 暂停
     */
    function pause(): void {
      counter.value?.transition.pause();
    }
    
    /**
     * 继续
     */
    function resume(): void {
      counter.value?.transition.resume();
    }
    </script>
    
  • Vue 2/3 均可通过 inited 事件获取到 xiaohe-transition 实例用于控制动画

    <template>
      <count-to :value="pandora" @inited="onCounterInited">
        <template #default="{ value }">
          <span>{{ value }}</span>
        </template>
      </count-to>
    </template>
    
    <script>
    import { CountTo } from "xiaohe-vue-count-to";
    
    export default {
      components: { CountTo },
      data() {
        return {
          pandora: 0
        };
      },
      created() {
        this.transition = null;
      },
      methods: {
        onCounterInited(transition) {
          this.transition = transition;
        },
        /**
         * 暂停
         */
        pause() {
          this.transition?.pause();
        },
        /**
         * 继续
         */
        resume() {
          this.transition?.resume();
        }
      }
    };
    </script>
    
属性(Props)
参数说明类型可选值默认值
value数值NumberLike-0
decimals小数位数NumberLike-0
duration动画时长(单位: ms)NumberLike-2000
preset预设曲线BezierCurvePresetLikelinear/ease/ease-in/ease-out/ease-in-outlinear
bezier自定义曲线(优先级高于preset)BezierCurve--
delay延迟开始时间(单位: ms)NumberLike-0
fps帧率NumberLike--1
decimal 0.3.0小数点string-.
use-group-value 0.3.0是否启用数值分组(示例:10000000.00 -> 10,000,000.00)boolean-false
use-indian-style-group 0.3.0是否使用印度风格数值分组(示例:10000000.00 -> 1,00,00,000.00)boolean-false
separator 0.3.0分隔符string-,
numerals 0.3.0自定义数字string[]--
事件(Events)
事件说明回调参数
initedtransition 初始化完成(instance: Transition)
change数值变化(value: string, instance: Transition)
started动画开始(instance: Transition)
paused动画暂停(instance: Transition)
resumed动画继续(instance: Transition)
stopped动画停止(instance: Transition)
completed动画完成(instance: Transition)
插槽(Slots)
名称说明类型
default默认内容{ value: string }
实例(Inst)
属性说明类型
transitionxiaohe-transition 实例Transition
类型定义

请查看 jsdocs.io

🛸 链接

🐶 讨论交流

🏆 开源协议

Keywords

FAQs

Package last updated on 16 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc