Skip to content

Commit

Permalink
perf: when tags-view scroll close the right-menu
Browse files Browse the repository at this point in the history
  • Loading branch information
dongxiaosun authored and PanJiaChen committed Jun 4, 2020
1 parent fe72cae commit b8c934c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/layout/components/TagsView/ScrollPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ export default {
return this.$refs.scrollContainer.$refs.wrap
}
},
mounted() {
this.scrollWrapper.addEventListener('scroll', this.emitScroll, true)
},
beforeDestroy() {
this.scrollWrapper.removeEventListener('scroll', this.emitScroll)
},
methods: {
handleScroll(e) {
const eventDelta = e.wheelDelta || -e.deltaY * 40
const $scrollWrapper = this.scrollWrapper
$scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4
},
emitScroll() {
this.$emit('scroll')
},
moveToTarget(currentTag) {
const $container = this.$refs.scrollContainer.$el
const $containerWidth = $container.offsetWidth
Expand Down
5 changes: 4 additions & 1 deletion src/layout/components/TagsView/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div id="tags-view-container" class="tags-view-container">
<scroll-pane ref="scrollPane" class="tags-view-wrapper">
<scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll">
<router-link
v-for="tag in visitedViews"
ref="tag"
Expand Down Expand Up @@ -191,6 +191,9 @@ export default {
},
closeMenu() {
this.visible = false
},
handleScroll() {
this.closeMenu()
}
}
}
Expand Down

0 comments on commit b8c934c

Please sign in to comment.