Skip to content

Commit

Permalink
feat: 选择图标时自动滚动到已选图标位置
Browse files Browse the repository at this point in the history
  • Loading branch information
huguangju committed Feb 19, 2021
1 parent d05bcaf commit 11b54e8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/views/index/IconsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
clearable
/>
</div>
<ul class="icon-ul">
<ul ref="iconWrap" class="icon-ul">
<li
v-for="icon in iconList"
:key="icon"
Expand Down Expand Up @@ -61,12 +61,21 @@ export default {
onOpen() {
this.active = this.current
this.key = ''
this.scrollToActive()
},
onClose() {},
onSelect(icon) {
this.active = icon
this.$emit('select', icon)
this.$emit('update:visible', false)
},
scrollToActive() {
this.$nextTick(() => {
const $activeItem = this.active
? document.getElementsByClassName('active-item')[0]
: this.$refs.iconWrap.childNodes[0]
$activeItem && $activeItem.scrollIntoView && $activeItem.scrollIntoView()
})
}
}
}
Expand Down

0 comments on commit 11b54e8

Please sign in to comment.