this.initScroll();
// 左右联动
// 右->左
// 计算区间
this.caculateHeight();
});
}
})
.catch(function(error) {
// handle error
console.log(error);
});
},
computed: {
// 根据右侧判断左侧index
currentIndex() {
for (let i = 0; i < this.listHeight.length; i++) {
let start = this.listHeight[i];
let end = this.listHeight[i + 1];
if (this.scrollY >= start && this.scrollY < end) {
return i;
}
}
return 0;
},
selectFoods() {
let foods = [];
this.goods.forEach(good => {
good.spus.forEach(food => {
if (food.count > 0) {
foods.push(food);
}
});
});
return foods;
}
},
methods: {
head_bg(imgName) {
return "background-image: url(" + imgName + ");";
},
initScroll() {
this.menuScroll = new BScroll(this.$refs.menuScroll, {
click: true
});
this.foodScroll = new BScroll(this.$refs.foodScroll, {
probeType: 3,
click: true
});
this.foodScroll.on("scroll", pos => {
this.scrollY = Math.abs(Math.round(pos.y));
});
},
caculateHeight() {
let foodList = this.$refs.foodScroll.getElementsByClassName(
"food-list-hook"
);//获取到dom元素
let height = 0;
this.listHeight.push(height);
for (let i = 0; i < foodList.length; i++) {
height += foodList[i].clientHeight;
this.listHeight.push(height);
}
// [0, 215, 1343, 2425, 3483, 4330, 5823, 7237, 8022, 8788, 9443] },
selectMenu(index) {
let foodlist = this.$refs.foodScroll.getElementsByClassName(
"food-list-hook"
);