From 93c3e70e98153d60051acf399ec9520e407d54dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=95=BE?= <1144797966@qq.com> Date: Sat, 3 Aug 2024 16:38:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8D=E8=B4=AD=E7=89=A9=E8=BD=A6=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E8=BF=9B=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/order_food/order_food.vue | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pages/order_food/order_food.vue b/pages/order_food/order_food.vue index 222d9f0..255e19f 100644 --- a/pages/order_food/order_food.vue +++ b/pages/order_food/order_food.vue @@ -483,6 +483,9 @@ if (this.cartLists && this.cartLists.data && this.cartLists.data.length >= 0) { this.setNumber() } + this.scrollTopSize = 0 + this.scrollHeight = 1000 + this.topArr = [] setTimeout(() => { this.getElementTop(); }, 100); @@ -833,6 +836,7 @@ /* 获取元素顶部信息 */ getElementTop() { + new Promise((resolve, reject) => { let view = uni.createSelectorQuery().selectAll('.main-item'); view.boundingClientRect(async data => { @@ -874,14 +878,14 @@ } } const lastElement = this.topArr[this.topArr.length - 1]; - const currentElement = this.topArr[this.leftIndex]; + const currentElement = this.topArr[index]; const diff = lastElement - currentElement; console.log(diff) - // if (diff > this.scrollHeight) { - this.leftIndex = (index < 0 ? 0 : index); - // } else { - // this.leftIndex = this.leftIndex - // } + if (diff > this.scrollHeight) { + this.leftIndex = (index < 0 ? 0 : index); + } else { + this.leftIndex = this.leftIndex + } } }, /* 左侧导航点击 */ @@ -890,9 +894,7 @@ scrollTop: this.topArr[index] - this.HeighT, duration: 0 }); - setTimeout(() => { - this.leftIndex = index - }, 500) + this.leftIndex = index } } }