|
21 | 21 | <view class="nut-elevator__list__fixed-title">{{ indexList?.[currentIndex]?.[acceptKey] }}</view> |
22 | 22 | </view> |
23 | 23 | <view v-show="scrollStart" v-if="indexList.length" class="nut-elevator__code--current"> |
24 | | - {{ |
25 | | - indexList[codeIndex][acceptKey] |
26 | | - }} |
| 24 | + {{ indexList[codeIndex][acceptKey] }} |
27 | 25 | </view> |
28 | 26 | <view class="nut-elevator__bars" @touchstart="touchStart" @touchmove.stop.prevent="touchMove" @touchend="touchEnd"> |
29 | 27 | <view class="nut-elevator__bars__inner"> |
|
36 | 34 | @click="handleClickIndex(item[acceptKey])" |
37 | 35 | > |
38 | 36 | {{ item[acceptKey] }} |
39 | | - </view |
40 | | - > |
| 37 | + </view> |
41 | 38 | </view> |
42 | 39 | </view> |
43 | 40 | </view> |
@@ -96,29 +93,25 @@ export default create({ |
96 | 93 | fixedTop: 0 |
97 | 94 | }) |
98 | 95 |
|
99 | | - const clientHeight = computed(() => { |
100 | | - return listview.value.clientHeight |
101 | | - }) |
| 96 | + const clientHeight = computed(() => listview.value.clientHeight) |
102 | 97 |
|
103 | 98 | const getData = (el: HTMLElement, name: string): string | void => { |
104 | 99 | const prefix = 'data-' |
105 | 100 | return el.getAttribute(prefix + name) as string |
106 | 101 | } |
107 | 102 |
|
108 | 103 | const setListGroup = (el: any) => { |
109 | | - nextTick(() => { |
110 | | - if (!state.listGroup.includes(el) && el != null) { |
111 | | - state.listGroup.push(el) |
112 | | - } |
113 | | - }) |
| 104 | + if (!state.listGroup.includes(el) && el != null) { |
| 105 | + state.listGroup.push(el) |
| 106 | + } |
114 | 107 | } |
115 | 108 |
|
116 | 109 | const calculateHeight = () => { |
117 | 110 | let height = 0 |
118 | 111 | state.listHeight.push(height) |
119 | 112 | for (let i = 0; i < state.listGroup.length; i++) { |
120 | 113 | let item = state.listGroup[i] |
121 | | - height += Math.floor(item.clientHeight) |
| 114 | + height += Math.round(item.clientHeight) |
122 | 115 | state.listHeight.push(height) |
123 | 116 | } |
124 | 117 | } |
@@ -166,20 +159,18 @@ export default create({ |
166 | 159 | } |
167 | 160 |
|
168 | 161 | const listViewScroll = (e: Event) => { |
169 | | - let target = e.target as Element |
170 | | - let scrollTop = target.scrollTop |
| 162 | + const target = e.target as Element |
| 163 | + const scrollTop = target.scrollTop |
171 | 164 | const listHeight = state.listHeight |
172 | | - state.scrollY = scrollTop |
| 165 | + state.scrollY = Math.round(scrollTop) |
173 | 166 | for (let i = 0; i < listHeight.length - 1; i++) { |
174 | | - let height1 = listHeight[i] |
175 | | - let height2 = listHeight[i + 1] |
176 | | - if (state.scrollY >= height1 && state.scrollY < height2) { |
| 167 | + const [startHeight, endHeight] = [listHeight[i], listHeight[i + 1]] |
| 168 | + if (state.scrollY >= startHeight && state.scrollY < endHeight) { |
177 | 169 | state.currentIndex = i |
178 | | - state.diff = height2 - state.scrollY |
| 170 | + state.diff = endHeight - state.scrollY |
179 | 171 | return |
180 | 172 | } |
181 | 173 | } |
182 | | -
|
183 | 174 | state.currentIndex = listHeight.length - 2 |
184 | 175 | } |
185 | 176 |
|
|
0 commit comments