Showing
1 changed file
with
15 additions
and
8 deletions
@@ -16,6 +16,12 @@ | @@ -16,6 +16,12 @@ | ||
16 | <script> | 16 | <script> |
17 | export default { | 17 | export default { |
18 | name: 'Scroller', | 18 | name: 'Scroller', |
19 | + props: { | ||
20 | + topDistance: { | ||
21 | + type: Number, | ||
22 | + default: 50 | ||
23 | + } | ||
24 | + }, | ||
19 | data() { | 25 | data() { |
20 | return { | 26 | return { |
21 | distance: 0, | 27 | distance: 0, |
@@ -54,7 +60,7 @@ export default { | @@ -54,7 +60,7 @@ export default { | ||
54 | this.startY = e.touches[0].clientY; | 60 | this.startY = e.touches[0].clientY; |
55 | if (this.$el.scrollTop === 0) { | 61 | if (this.$el.scrollTop === 0) { |
56 | this.transition = false; | 62 | this.transition = false; |
57 | - this.topStatus = ''; | 63 | + this.topStatus = 'pull'; |
58 | } | 64 | } |
59 | }, | 65 | }, |
60 | touchmove(e) { | 66 | touchmove(e) { |
@@ -63,9 +69,9 @@ export default { | @@ -63,9 +69,9 @@ export default { | ||
63 | 69 | ||
64 | this.direction = distance > 0 ? 'down' : 'up'; | 70 | this.direction = distance > 0 ? 'down' : 'up'; |
65 | 71 | ||
66 | - if (this.direction === 'down' && this.$el.scrollTop === 0) { | 72 | + if (this.direction === 'down' && this.$el.scrollTop === 0 && this.topStatus) { |
67 | this.distance = distance; | 73 | this.distance = distance; |
68 | - if (this.distance > 50) { | 74 | + if (this.distance > this.topDistance) { |
69 | this.topStatus = 'drag'; | 75 | this.topStatus = 'drag'; |
70 | } | 76 | } |
71 | } | 77 | } |
@@ -73,17 +79,18 @@ export default { | @@ -73,17 +79,18 @@ export default { | ||
73 | touchend() { | 79 | touchend() { |
74 | if (this.direction === 'down' && this.$el.scrollTop === 0) { | 80 | if (this.direction === 'down' && this.$el.scrollTop === 0) { |
75 | this.transition = true; | 81 | this.transition = true; |
76 | - if (this.topStatus) { | 82 | + if (this.topStatus === 'drag') { |
77 | this.styleTop = { | 83 | this.styleTop = { |
78 | marginTop: '0' | 84 | marginTop: '0' |
79 | }; | 85 | }; |
80 | - } | ||
81 | - if (this.distance > 50 && !this.isLoading) { | ||
82 | - this.isLoading = true; | ||
83 | - this.$emit('loading'); | 86 | + if (!this.isLoading) { |
87 | + this.isLoading = true; | ||
88 | + this.$emit('loading'); | ||
89 | + } | ||
84 | } | 90 | } |
85 | this.distance = 0; | 91 | this.distance = 0; |
86 | } | 92 | } |
93 | + this.topStatus = ''; | ||
87 | } | 94 | } |
88 | } | 95 | } |
89 | }; | 96 | }; |
-
Please register or login to post a comment