@@ -55,20 +55,7 @@ export default {
55
55
},
56
56
mounted () {
57
57
if (getScrollTop () == 0 ) this .rollbackTop = true
58
- window .addEventListener (
59
- ' scroll' ,
60
- () => {
61
- const nowTopPos = getScrollTop ()
62
- if (nowTopPos - this .lastTopPos > 0 ) {
63
- this .setRollBack (false )
64
- this .rollbackTop = false
65
- } else if (nowTopPos == 0 ) {
66
- this .rollbackTop = true
67
- } else this .setRollBack (true )
68
- this .lastTopPos = nowTopPos
69
- },
70
- false
71
- )
58
+ window .addEventListener (' scroll' , this .scrollHandler )
72
59
window .addEventListener (' resize' , this .resizeHandler )
73
60
},
74
61
computed: {
@@ -86,6 +73,17 @@ export default {
86
73
closeSearch () {
87
74
this .searchVisible = false
88
75
},
76
+ scrollHandler () {
77
+ const nowTopPos = getScrollTop ()
78
+ // nowTopPos this.lastTopPos在移动端可为负数
79
+ if (nowTopPos >= 0 && this .lastTopPos >= 0 && nowTopPos - this .lastTopPos > 0 ) {
80
+ this .setRollBack (false )
81
+ this .rollbackTop = false
82
+ } else if (nowTopPos <= 0 ) {
83
+ this .rollbackTop = true
84
+ } else this .setRollBack (true )
85
+ this .lastTopPos = nowTopPos
86
+ },
89
87
resizeHandler: debounce (function () {
90
88
const width = document .documentElement .clientWidth
91
89
@@ -94,6 +92,10 @@ export default {
94
92
this .drawer = false
95
93
}
96
94
}, 200 )
95
+ },
96
+ destroyed () {
97
+ window .removeEventListener (' scroll' , this .scrollHandler )
98
+ window .removeEventListener (' resize' , this .resizeHandler )
97
99
}
98
100
}
99
101
</script >
0 commit comments