將json動圖放進頁面


有次意外得知,UI出的動圖,可以轉成json,然后前端用插件可以當做圖片顯示

1.安裝lottie-web

2.引入lottie-web和JSON動畫

import lottie from 'lottie-web'
import animationData from '~/static/data' // 引入json文件
<div class="animate" id="circle">

3.執行方法

mounted(){
  const params = {
    container: document.getElementById('circle'),
    renderer: 'svg',
    loop: true,
    autoplay: true,
    animationData: animationData
  };

  this.anim = lottie.loadAnimation(params);

},

4.組件卸載時摧毀

 destroyed () {
      this.anim.destroy()
    }

效果圖:

JSON動畫代碼可以去這個網站下載

 https://lottiefiles.com/

每天進步一點點

 
        
 
         
         
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM