uniapp 讓一個“貓”跑起來(uni.createAnimation())

cart.vue

<template>
    <view class="search-content">
        <view class="search-header" style="font-size: 30px; padding-bottom: 20px;font-weight: bold;display: flex;justify-content: space-around;flex-direction: row;">
            <view class="all">
                <text @click="backAnimation()">出去</text>
            </view>
            <view class="all">
                <text @click="goAnimation()">回來</text>
            </view>
            <view class="all">
                <text @click="rotateAnimation()">打滾</text>
            </view>
        </view>
        <view class="search-header">
            <view class="collapse-item" :animation="animationData" style="font-size: 40px;">
                奶牛貓
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                animationData: {},
            }
        },
        onLoad(option) {
            this.animation = uni.createAnimation()
        },
        methods: {
            goAnimation() {
                this.animation.translateX(200).step()
                    .translateY(200).step()
                    .translateX(0).step()
                    .translateY(0).step()
                this.animationData = this.animation.export()
            },
            backAnimation() {
                this.animation.translateX(0).step()
                    .translateY(0).step()
                    .translateX(200).step()
                    .translateY(200).step()
                this.animationData = this.animation.export()
            },
            rotateAnimation() {
                this.animation.rotateX(0).step()
                    .rotateX(90).step()
                    .rotateX(180).step()
                    .rotateX(90).step()
                    .rotateX(0).step()
                this.animationData = this.animation.export()
            }
        }
    }
</script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章