Hanzi Weiter的简单应用小案例,在HTML汉字的书写,演示汉字笔画顺序的 汉字笔画库 js vue案例实例

因为业务需求,上网查询之后写的一个小 demo,参考文档https://hanziwriter.org/
**

具体实现

**
在 script 标签加载 Hanzi Writer
只需将以下内容放入你的网页的头部,自己的,或者从官网查看

在这里插入图片描述

js vue应用

 watch: {
      form (val) {
        this.username = this.form.name.replace('-', '').split('')
        this.$nextTick(() => {
          /* 先开始写字 */
          let hanziBox = document.getElementById('name0');
          let box_width = hanziBox.offsetWidth, box_height = hanziBox.offsetHeight;
          let writerConfig = {
            width: box_width,
            height: box_height,
            padding: 3,
            showOutline: false,
            showCharacter: false,
            strokeColor: '#FF9435',//字的颜色
            strokeAnimationSpeed: 2, // 5x normal speed
            delayBetweenStrokes: 20, // milliseconds
          };
          this.drawCharacter(0, writerConfig)
        })
      },
      animationQueue(){
        this.canvans()
      },
    },
    methods: {
      /* 文字书写方法 */
      drawCharacter (index = 0, config) {
        return new Promise(resolve => {
          let name = HanziWriter.create('name' + index, this.username[index], config);
          name.animateCharacter().then(() => {
            if (this.username[index + 1]) {
              this.drawCharacter(index + 1, config)
            }
          });
        })
      },
      /* 改定时器为Promise函数,方便async处理 */
      setTimer (callback, time = 0) {
        return new Promise(resolve => {
          setTimeout(function () {
            callback ? callback() : null
            resolve()
          }, time)
        })
      },
      //进度条
      async animationFun () {
        const that = this;
        that.animationQueue+=1;
          setTimeout(function () {
            if (that.animationQueue<=2) {
              that.animationFun()
            }else {
              that.subBtn = true;
            }
          }, 2500)

      },
   

    }

HTMl部分

<div class="name-box">
     <div class="firstname" :id="'name'+index" v-for="(item,index) in username"></div>
 </div>

css部分


  .name-box {
    display: flex;
    flex-direction: row;
    justify-content: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .firstname {
    width: 1.2rem;
    height: 1.2rem;
    font-size: 1.06rem;
    font-weight: 800;
  }

效果
在这里插入图片描述在这里插入图片描述


这里简单写了一下Hanzi Weiter的用法,Hanzi Weiter具体教程点击右侧了解,[特别鸣谢Hanzi Weiter网站]https://hanziwriter.org/

***(https://hanziwriter.org/cn/docs.html#other-methods-link)

更多内容

求关注,微信公众号-前端程序猿Pro,不至于前端~
在这里插入图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值