Page({
data: {
commentHeight: 300,
showDetail: false
},
onLoad: function () {
const { windowHeight } = wx.getWindowInfo()
const query = wx.createSelectorQuery()
query.select('.navbar').boundingClientRect()
query.select('#video-player').boundingClientRect()
query.exec(([ nav, video ]) => {
this.setData({
commentHeight: `${windowHeight - nav.height - video.height}`
})
})
},
showAnim: function() {
console.log(this.data.commentHeight)
this.animate('.block', [
{ translateY: this.data.commentHeight },
{ translateY: 0 },
], 2400, () => {
this.clearAnimation('.block')
})
},
change: function () {
this.setData({
showDetail: true
})
wx.nextTick(() => {
this.showAnim()
})
}
})
如此动画没效果,改成一个常量值 动画生效
![](https://mmbiz.qpic.cn/mmbiz_gif/N6aVLTb3Ky2H3aduOKbUCuwl6osYkcN6UNcTpyVBgf1Z3L9UfGrCt82tmy4IVzwcpzaxs3IymRWrhV0iapeM3QQ/0?wx_fmt=gif)