Browse Source

滚动居中

master
jiazhipeng 6 months ago
parent
commit
979d245dec
  1. 2
      app.js
  2. 11
      subPackages/foodNew/index.js
  3. 4
      subPackages/foodNew/index.wxml

2
app.js

@ -38,7 +38,7 @@ App({
// 获取前端配置文件
commonApi._post("pbservice/Other/getClientConfig", {unique_key: "wechatxcx"}).then(res => {
let data = JSON.parse(res.data);
data.isTest = data.isTest140? true : false;
data.isTest = data.isTest142? true : false;
data.indexSeason = null
this.globalData.configJson = data
}).then(() => {

11
subPackages/foodNew/index.js

@ -49,6 +49,8 @@ Page({
lon: null,
lat: null,
scrollLeft: 0,
scrollDom: "",
scrollDomLeft:0,
windowWidth: 375,
prod_phone: "",
},
@ -128,10 +130,15 @@ Page({
console.log(rect)
if (rect) {
let targetScrollLeft = rect.left + (rect.width / 2) - (windowWidth / 2)+_this.data.scrollLeft;
console.log(e, targetScrollLeft)
console.log((rect.width / 2) - (windowWidth / 2))
this.setData({
scrollLeft: targetScrollLeft
scrollLeft: targetScrollLeft||0,
scrollDomLeft: (rect.width / 2) - (windowWidth / 2),
});
this.setData({
scrollDom: domId,
})
}
}).exec()

4
subPackages/foodNew/index.wxml

@ -19,7 +19,9 @@
<view style="height: 20rpx;width: 100%;background: #F7F7F7;"></view>
<scroll-view scroll-x scroll-with-animation enable-flex scroll-left="{{scrollLeft}}" id="menus"
<scroll-view scroll-x scroll-with-animation enable-flex id="menus"
scroll-into-view="{{scrollDom}}" scroll-into-view-offset="{{scrollDomLeft}}"
class="scroll-menus{{fixed?' fixed-menus':''}}" style="top:{{top}}px" wx:if="{{supplierInfo&&supplierInfo.products.length>0}}">
<view id="scrollView{{index}}" class="scroll-menu-item {{idIndex==index?'active':''}}"
wx:for="{{supplierInfo.products}}" data-item="{{item}}" data-index="{{index}}"

Loading…
Cancel
Save