2***@qq.com
2***@qq.com
  • 发布:2024-08-01 17:25
  • 更新:2024-08-23 17:37
  • 阅读:118

【报Bug】手机端调试css的@keyframes过渡动画无效

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 10 专业版

HBuilderX类型: 正式

HBuilderX版本号: 4.15

手机系统: HarmonyOS NEXT

手机系统版本号: HarmonyOS NEXT Developer Beta2

手机厂商: 华为

手机机型: HUAWEI P50E

页面类型: vue

vue版本: vue3

打包方式: 离线

项目创建方式: HBuilderX

示例代码:
<template>  
    <view class="backgroundArea">  
        <view v-for="(pattern, index) in patternsList"   
        class="backgroundPattern"  
        :style="getStyle(index)">  
        </view>  
    </view>  
</template>  

<script>  
    class Pattern {  
        constructor(num) {  
            this.num = num,  
            this.width = '',  
            this.opacity = '',  
            this.left = '',  
            this.bottom = '',  
            this.top = '',  
            this.moveTime = '',  
            this.delay = '',  
            this.windowHeight = '',  
            this.timer = null,  
            this.animation = {}  
        }  

        reRandom() {  
            uni.getSystemInfo({  
                success: (res) => {  
                    this.windowHeight = res.windowHeight  
                    var maxWidth = 0.25 * res.windowWidth  
                    var minWidth = 0.1 * res.windowWidth  
                    this.width = Math.random() * (maxWidth - minWidth) + minWidth  
                    var speed = ((this.windowHeight + 2 * 1.3 * this.width) / 5000) * this.width * 0.005  
                    this.moveTime = (this.windowHeight + 2 * 1.3 * this.width) / speed  
                    var maxLeft = res.windowWidth + 2 * this.width  
                    this.opacity = Math.sin(0.01 * this.width)  
                    this.left = Math.random() * maxLeft - this.width  
                    this.bottom = -1.3 * this.width  
                    this.top = res.windowHeight + 2 * this.width * 1.3  
                    this.delay = 100000 * 1 / this.width  
                }  
            })  
        }  
    }  

    export default {  
        name: 'activeBackground',  
        data() {  
            return {  
                patternsList: []  
            }  
        },  
        created() {  
            for (let i = 0; i < 20; i++) {  
                var pattern = new Pattern(i)  
                pattern.reRandom()  
                this.patternsList.push(pattern)  
            }  
        },  
        methods: {  
            getStyle(index) {  
                return {  
                    width: this.patternsList[index].width + 'px',  
                    height: 1.3 * this.patternsList[index].width + 'px',  
                    opacity: this.patternsList[index].opacity,  
                    left: this.patternsList[index].left + 'px',  
                    bottom: this.patternsList[index].bottom + 'px',  
                    animation: 'move ' + this.patternsList[index].moveTime + 'ms infinite linear',  
                }  
            }  
        }  
    }  
</script>  

<style>  
    .backgroundArea {  
        width: 100%;  
        height: 100%;  
    }  

    @keyframes move {  
        0% {  
            bottom: calc(25vw * -1.3 - 100px);  
        }  
        100% {  
            bottom: calc(100% + 25vw * 1.3);  
        }  
    }  

    .backgroundPattern {  
        position: absolute;  
        background-color: white;  
        border-radius: 20%;  
    }  
</style>

操作步骤:

组件代码粘贴后编译运行即可。运行到浏览器均可播放,运行在手机app上不能播放

预期结果:

预期是像附件中的gif那样在手机端播放

实际结果:

如图2一片空白,没有显示播放

bug描述:

采用css过渡动画实现循环的过渡动画效果,在h5调试可行,但是在app真机调试中无法显示出来。css的animation其他动画效果在手机app调试没有问题,唯独使用@keyframes实现过度动画效果不能在手机app上播放。控制器无报错,但是不能正常播放

2024-08-01 17:25 负责人:无 分享
已邀请:
DCloud_UNI_BFC

DCloud_UNI_BFC

你好,style下面的 keyframes的move动画编译后会自动加hash值,所以不能直接动态 将move动画赋值给元素。

方案一,将动画move 动画 定义移动到app.vue里面, 这样就设置为全局。
方案二, 将动画move 移动到一个class类名里面, 然后动态添加这个class名

h5能正常运行是因为热更新的bug,丢失了css的hash。 感谢反馈。已加分

要回复问题请先登录注册