Browse Source

优化商品分类选中效果

feature/feature-compatible
wenghaocan 7 years ago
parent
commit
026abc452f
1 changed files with 37 additions and 3 deletions
  1. 40
      src/view/goods-classify.vue

40
src/view/goods-classify.vue

@ -61,11 +61,12 @@
goodsList: [], goodsList: [],
imghost: "http://medou.oss-cn-shenzhen.aliyuncs.com/", imghost: "http://medou.oss-cn-shenzhen.aliyuncs.com/",
listHeight: [], // listHeight: [], //
scrollY: {}
scrollY: {},
currentNum: 0
} }
}, },
computed: { computed: {
currentIndex () {
/*currentIndex () {
const { scrollY, listHeight } = this const { scrollY, listHeight } = this
let index = listHeight.findIndex((height, index) => { let index = listHeight.findIndex((height, index) => {
return scrollY >= listHeight[index] && scrollY < listHeight[index + 1] return scrollY >= listHeight[index] && scrollY < listHeight[index + 1]
@ -74,6 +75,26 @@
index++ index++
} }
return index return index
}*/
currentIndex(){
for (let i = 0; i < this.listHeight.length; i++){
let height = this.listHeight[i]
let height2 = this.listHeight[i + 1]
//height2heightheight2
//>=height,this.scrollY=0,height=0
if( !height2 || (this.scrollY >= height && this.scrollY < height2)) {
return i
}
if(this.listHeight[this.listHeight.length-1] - this.$refs.foodWrapper.clientHeight <= this.scrollY ) {
if(this.clickTrue) {
return this.currentNum
} else {
return (this.listHeight.length-1)
}
}
}
return 0
} }
}, },
components: { components: {
@ -152,13 +173,26 @@
this.listHeight.push(height); this.listHeight.push(height);
} }
}, },
selectMenu(index, event) {
/*selectMenu(index, event) {
if(event && !event._constructed) { if(event && !event._constructed) {
return ; return ;
} }
let foodList = this.$refs.foodWrapper.getElementsByClassName("food-list-hook"); let foodList = this.$refs.foodWrapper.getElementsByClassName("food-list-hook");
let el = foodList[index]; let el = foodList[index];
this.foodsScroll.scrollToElement(el,300) this.foodsScroll.scrollToElement(el,300)
},*/
selectMenu(index, event){
this.clickTrue = true //clickTruetrue
this.currentNum = index
//better-scrolleventevent_constructed
// _constructedreturn
if (event && !event._constructed){
return
} else {
let foodList = this.$refs.foodWrapper.getElementsByClassName("food-list-hook");
let el = foodList[index];
this.foodsScroll.scrollToElement(el,300)
}
}, },
autoSelect() { autoSelect() {
for (let i = 0; i < this.goodsList.length; i++) { for (let i = 0; i < this.goodsList.length; i++) {

Loading…
Cancel
Save