|
@@ -20,10 +20,12 @@ Component({
|
|
|
// 获取屏幕宽高
|
|
|
const systemInfo = wx.getWindowInfo();
|
|
|
const isAndroid = systemInfo.platform === 'android'
|
|
|
- const isDevtools = systemInfo.platform === 'devtools'
|
|
|
- const barHeight = !isAndroid ?
|
|
|
+ // const isDevtools = systemInfo.platform === 'devtools'
|
|
|
+ const barHeight = !isAndroid ? 44 : 48;
|
|
|
+
|
|
|
const globalTop = app.globalData.top
|
|
|
this.setData({
|
|
|
+ maxTop: barHeight + systemInfo.safeArea.top,
|
|
|
windowWidth: systemInfo.windowWidth,
|
|
|
windowHeight: systemInfo.windowHeight,
|
|
|
top: globalTop
|
|
@@ -74,9 +76,9 @@ Component({
|
|
|
const distanceTop = top;
|
|
|
const moveHeight = top + elementHeight
|
|
|
// 判断元素与顶部和底部的距离,选择最近的边界
|
|
|
- if (distanceTop < 0) {
|
|
|
- this.setData({ top: 0 }, () => {
|
|
|
- app.globalData.top = 0
|
|
|
+ if (distanceTop < this.data.maxTop) {
|
|
|
+ this.setData({ top: this.data.maxTop }, () => {
|
|
|
+ app.globalData.top = this.data.maxTop
|
|
|
}); // 吸附到顶部
|
|
|
} else if(moveHeight >= windowHeight) {
|
|
|
this.setData({ top: windowHeight - elementHeight }, () => {
|