Skip to content

Commit 11b54e8

Browse files
author
huguangju
committed
feat: 选择图标时自动滚动到已选图标位置
1 parent d05bcaf commit 11b54e8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/views/index/IconsDialog.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
clearable
2020
/>
2121
</div>
22-
<ul class="icon-ul">
22+
<ul ref="iconWrap" class="icon-ul">
2323
<li
2424
v-for="icon in iconList"
2525
:key="icon"
@@ -61,12 +61,21 @@ export default {
6161
onOpen() {
6262
this.active = this.current
6363
this.key = ''
64+
this.scrollToActive()
6465
},
6566
onClose() {},
6667
onSelect(icon) {
6768
this.active = icon
6869
this.$emit('select', icon)
6970
this.$emit('update:visible', false)
71+
},
72+
scrollToActive() {
73+
this.$nextTick(() => {
74+
const $activeItem = this.active
75+
? document.getElementsByClassName('active-item')[0]
76+
: this.$refs.iconWrap.childNodes[0]
77+
$activeItem && $activeItem.scrollIntoView && $activeItem.scrollIntoView()
78+
})
7079
}
7180
}
7281
}

0 commit comments

Comments
 (0)