animation-view.uvue 1.9 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<template>
  <view class="content">
    <animation-view class="animation" :path="path" :loop="loop" :autoplay="autoplay" :action="action" :hidden="hidden"
      @bindended="lottieEnd">
    </animation-view>
    <button class="button" @click="playLottie" type="primary">{{status}}lottie动画</button>
    <button class="button" @click="changeLottie" type="primary">切换{{location}}动画</button>
    <text class="tips">注意:uts组件插件animation-view需要使用自定义基座才能生效!</text>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        path: '/uni_modules/uni-animation-view/static/lottie.json',
        loop: false,
        autoplay: false,
        action: 'stop',
        hidden: false,
        status: '播放',
        location: '网络'
      }
    },
    methods: {
      playLottie() {
        this.action = ('play' !== this.action) ? 'play' : 'pause';
        this.status = ('pause' === this.action) ? '播放' : '暂停';
      },
      changeLottie() {
        this.action = 'stop';
        this.status = '播放';
        this.path = ('网络' === this.location) ? 'https://native-res.dcloud.net.cn/uni-app/static/lottie.json' :
          '/uni_modules/uni-animation-view/static/lottie.json';
        this.location = ('网络' === this.location) ? '本地' : '网络';
        console.log('path=' + this.path);
      },
      lottieEnd() {
        this.status = '播放';
        this.action = 'stop';
        console.log('动画播放结束');
      }
    }
  }
</script>

<style>
  .content {
    display: flex;
    flex: 1;
    align-items: center;
  }

  .animation {
    width: 750rpx;
    height: 300rpx;
    background-color: #CCCCCC;
    margin-bottom: 20px;
  }

  .button {
    width: 640rpx;
    margin: 10px;
  }

  .tips {
    margin: 20px;
    color: darkred;
  }
</style>