动画的height,不能用百分比?
发布于 5 年前 作者 yijun 8500 次浏览 来自 问答

height动画,设置单位rpx、px、vh都没问题。

但是改成百分比的,就是瞬间变化,没有动画的渐变效果了。

求帮助这么回事?bug还是我用的有问题?

<view style=‘background-color: red;’ animation="{{an}}">

    <view style=‘height:300rpx’></view>

</view>

const app = getApp()
Page({
  data: {
    an:{}
  },
  onShow: function () {
    let a = wx.createAnimation({
      duration: 200
    });
    let i=1;
    setInterval(()=>{
       
      //正常
      // this.setData({
      //   an: a.height(i%2==0?300:0).step().export()
      // });
 
      //无动画效果
      this.setData({
        an: a.height(i % 2 == 0 ? '100%' : 0).step().export()
      });
      i++;
    },500);
  },
})
1 回复

给他的父标签一个高度,如果这个根标签,就设个

page{

    height:100%;

}

回到顶部