传播星球
传播星球
  • 发布:2024-07-02 14:22
  • 更新:2024-07-02 16:38
  • 阅读:58

nvue 页面怎么使用 animation动画

分类:uni-app

在css里写上animation控制台就会警告不支持,要怎么实现下面代码的这个动画效果啊

animation: scaleDraw 0.5s ease-in-out;
@keyframes scaleDraw{
0% {
margin-bottom: 0;
}
25% {
margin-bottom: 32px;
}
50% {

        margin-bottom: 0px;  
    }  
    75% {  
        margin-bottom: 16px;  
    }  
    100%{  
        margin-bottom: 0px;  
    }  

  }
2024-07-02 14:22 负责人:无 分享
已邀请:
传播星球

传播星球 (作者)

试了好多种方法都不行,有什么方式能代替吗

爱豆豆

爱豆豆 - 办法总比困难多

animation没有marginBottom属性 用height代替了 效果差不多 你试试
参考文档:https://uniapp.dcloud.net.cn/api/ui/animation.html

<template>  
    <view>  
        <view :animation="animationData"></view>  
        <button @tap="tapBtn">开始动画</button>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                animationData: {},  
            }  
        },  
        methods: {  
            tapBtn() {  
                let animation = uni.createAnimation({  
                    duration: 150,  
                    timingFunction: 'ease-in-out',  
                })  
                animation.height(0).step()  
                animation.height(32).step()  
                animation.height(0).step()  
                animation.height(16).step()  
                animation.height(0).step()  
                this.animationData = animation.export();  
            },  
        }  
    }  
</script>  

<style>  

</style>
  • 传播星球 (作者)

    我用你提供的代码,没有任何效果啊

    2024-07-02 16:02

  • 爱豆豆

    回复 传播星球: 测错了 测的h5 不好意思 下面有人回答了 你看下

    2024-07-02 16:46

  • 爱豆豆

    回复 传播星球: 直接控制样式也可以实现类似效果的


    <template>  
    <view style="height: 100vh;">
    <view class="view-animation" :style="{
    height:height 'px'
    }"></view>
    <button @click="tapBtn">开始动画</button>
    </view>
    </template>
    <script>
    export default {
    data() {
    return {
    height: 0,
    };
    },
    methods: {
    delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
    },
    async tapBtn() {
    this.height = 32
    await this.delay(100)
    this.height = 0
    await this.delay(200)
    this.height = 16
    await this.delay(100)
    this.height = 0
    }
    }
    };
    </script>
    <style lang="scss" scoped>
    .view-animation {
    transition-property: height;
    transition-duration: 0.4s;
    transition-timing-function: ease-in-out;
    }
    </style>

    2024-07-02 17:18

十二112

十二112

使用bindingx,没有margin,通过height实现
在需要margin地方中间插入一个空view,修改高度来实现同样的动画效果

<template>  
    <view class="content">  
        <view ref="empty"></view>  
        <button @tap="handleStart">开始动画</button>  
        <button @tap="handleStop">停止动画</button>  
    </view>  
</template>  

<script>  
    const Binding = uni.requireNativePlugin('bindingx')  
    export default {  
        data() {  
            return {  
                steps: [32,0,16,0],  
                animationStatus: false,  
            }  
        },  
        methods: {  
            handleStart() {  
                if(this.animationStatus) return  
                this.animationStatus = true  
                this.startAnimation(0)  
            },  
            handleStop() {  
                this.animationStatus = false  
            },  
            startAnimation(i) {  
                const current = this.steps[i]  
                const prev = this.steps[i - 1] || this.steps[this.steps.length - 1]  
                const token = Binding.bind({  
                    eventType: 'timing',  
                    exitExpression: 't>125',  
                    props: [  
                        {  
                            element: this.$refs.empty.ref,  
                            property: 'height',  
                            expression: `easeInOutQuint(t,${prev},0+${current - prev},125)`  
                        },  
                    ],  
                },(result) => {  
                    if(result.state == 'exit') {  
                        Binding.unbind(token)  
                        i++  
                        this.animationStatus && this.startAnimation(i == this.steps.length ? 0 : i)  
                    }  
                })  
            }  
        }  
    }  

</script>

要回复问题请先登录注册