把svg图标制作成字体图标_创建2状态SVG驱动的动画图标

本文介绍如何使用vue-svg-transition将SVG图标转换为字体图标,实现2状态动画效果。通过npm安装并导入Vue和SvgTransition,设置尺寸、过渡时间和触发方式,轻松创建动画图标。

把svg图标制作成字体图标

vue-svg转换 (vue-svg-transition)

Create 2-state, SVG-powered animated icons.

创建由SVG驱动的2状态动画图标。

vue-svg-transitionv

快速开始 (Quick start)

npm install --save vue-svg-transition
import Vue from 'vue';
import SvgTransition from 'vue-svg-transition';

Vue.use(SvgTransition);

范本范例 (Template Example)

It is recommended to use vue-svg-loader so we can import our SVGs from external files. But it's possible to use inline SVG as well.

建议使用vue-svg-loader以便我们可以从外部文件导入vue-svg-loader 。 但是也可以使用内联SVG。

<template>
    <svg-transition :size="size">
        <MyIcon slot="initial" />
        <MyOtherIcon />
    </svg-transition>
</template>

<script>
import MyIcon from "./assets/MyIcon.svg";
import MyOtherIcon from "./assets/MyOtherIcon.svg";

export default {
    components: {
        MyIcon,
        MyOtherIcon
    }
    data() {
        return {
            size: {
                width: 48,
                height: 48
            }
        }
    }
}
</script>

Trigger programmatically via ref

通过ref编程方式触发

<svg-transition ref="transition" trigger="none">
<!-- your icons -->
</svg-transition>

<script>
export default {
    mounted() {
        this.$refs.transition.performTransition();
    }
}
</script>

文献资料 (Documentation)

道具 (Props)

size

尺寸

The size of the SVG viewbox.

SVG视图框的大小。

  • type: Object

    类型: Object

  • default: { width: 32, height: 32 }

    默认值: { width: 32, height: 32 }

duration

持续时间

The duration of the transition in ms

过渡持续时间(毫秒)

  • type: Number

    类型: Number

  • default: 200

    默认值: 200

trigger

触发

The action that triggers the transition. Can be click, hover or none (if you want to trigger it programmatically).

触发过渡的动作。 可以clickhovernone click (如果要以编程方式触发它)。

  • type: String

    类型: String

  • default: click

    默认值: click

插槽 (Slots)

initial

初始

The SVG that will be initially displayed

最初显示的SVG

default

默认

The other SVG that will be transitioned to

另一个将转换到的SVG

翻译自: https://vuejsexamples.com/create-2-state-svg-powered-animated-icons/

把svg图标制作成字体图标

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值