Jelajahi Sumber

menuList跟随滚动

contra999 8 tahun lalu
induk
melakukan
c9894d6741
1 mengubah file dengan 7 tambahan dan 1 penghapusan
  1. 7 1
      src/components/goods/goods.vue

+ 7 - 1
src/components/goods/goods.vue

@@ -4,7 +4,7 @@
       <div class="menu-wrapper" ref="menuWrapper">
         <ul>
           <li v-for="(item,index) in goods" class="menu-item" :class="{'current':currentIndex===index}"
-              @click="selectMenu(index,$event)">
+              @click="selectMenu(index,$event)" ref="menuList">
           <span class="text border-1px">
             <span v-show="item.type>0" class="icon" :class="classMap[item.type]"></span>{{item.name}}
           </span>
@@ -74,6 +74,7 @@
           let height1 = this.listHeight[i];
           let height2 = this.listHeight[i + 1];
           if (!height2 || (this.scrollY >= height1 && this.scrollY < height2)) {
+            this._followScroll(i);
             return i;
           }
         }
@@ -156,6 +157,11 @@
           height += item.clientHeight;
           this.listHeight.push(height);
         }
+      },
+      _followScroll(index) {
+        let menuList = this.$refs.menuList;
+        let el = menuList[index];
+        this.meunScroll.scrollToElement(el, 300, 0, -100);
       }
     },
     components: {