From 8cb92dc6f52d5b2ae0afd67d9560352fdacacde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=95=BE?= <1144797966@qq.com> Date: Mon, 5 Aug 2024 17:52:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E8=81=94=E5=8A=A8?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/order_food/order_food.vue | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/pages/order_food/order_food.vue b/pages/order_food/order_food.vue index fd8b4e0..55fc4aa 100644 --- a/pages/order_food/order_food.vue +++ b/pages/order_food/order_food.vue @@ -35,7 +35,7 @@ 本店招牌菜 - + @@ -92,7 +92,8 @@ - + {{item.name}} @@ -108,7 +109,7 @@ - @@ -353,7 +354,8 @@ salePrice: '', //钱数 cartListsdatashow: false, //是否显示购物车 showCart: false, - lastbottom: '' //元素最低端的距离 + lastbottom: '', //元素最低端的距离 + scrollxleft: false } }, onPageScroll(e) { @@ -870,7 +872,7 @@ // this.scrollHeight = this.scrollHeight - this.HeighT this.topArr = topArr; // 获取最后一个元素最低端的盒子到顶点的距离 - this.lastbottom = res[res.length - 1].bottom; + this.lastbottom = res[res.length - 1].bottom - 20; /* 获取最后一项的高度,设置填充高度。判断和填充时做了 +-20 的操作,是为了滚动时更好的定位 */ let last = res[res.length - 1].height; if (last - 20 < this.scrollHeight) { @@ -889,21 +891,25 @@ let scrollFn = () => { let top = e.scrollTop; let index = 0; - /* 查找当前滚动距离 */ - for (let i = (this.topArr.length - 1); i >= 0; i--) { - /* 在部分安卓设备上,因手机逻辑分辨率与rpx单位计算不是整数,滚动距离与有误差,增加2px来完善该问题 */ - if ((top + 2) >= this.topArr[i] - this.HeighT) { - index = i; - break; - } - // const lastElement = this.topArr[this.topArr.length - 1]; - } - const currentElement = this.topArr[index]; - const diff = this.lastbottom - currentElement; - if (diff > this.scrollHeight - 200) { //200是固定高度 - this.leftIndex = (index < 0 ? 0 : index); + // 判断左边是否可以滑动 + if (top + 2 > this.topArr[0]) { + this.scrollxleft = true } else { + this.scrollxleft = false + } + /* 查找当前滚动距离 */ + if (this.scrollHeight - 200 >= (this.topArr[this.topArr.length - 1] - this.topArr[this + .leftIndex])) { //4109 this.leftIndex = this.leftIndex + } else { + for (let i = (this.topArr.length - 1); i >= 0; i--) { + /* 在部分安卓设备上,因手机逻辑分辨率与rpx单位计算不是整数,滚动距离与有误差,增加2px来完善该问题 */ + if ((top + 2) >= this.topArr[i] - this.HeighT) { + index = i; + break; + } + } + this.leftIndex = (index < 0 ? 0 : index); } } }, @@ -1700,7 +1706,7 @@ } .items { - height: 180rpx; + height: 90px; position: relative; font-weight: 400; font-size: 24rpx;