scroll-view.vue
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<Scroll ref="scroll" class="scroll-view" v-bind="attrMerge" v-on="listenerMerge">
<slot slot="default"></slot>
<template slot="pulldown" slot-scope="props">
<div v-if="props.pullDownRefresh"
class="pulldown-wrapper"
:style="props.pullDownStyle">
<div class="pulldown-content">
<div v-show="props.beforePullDown">
<div id="beforePullDown"></div>
</div>
<div v-show="!props.beforePullDown">
<div id="afterPullDown"></div>
</div>
</div>
</div>
</template>
</Scroll>
</template>
<script>
import {Scroll} from 'cube-ui';
export default {
name: 'ScrollView',
mounted() {
this.$nextTick(() => {
this._initLottie();
});
},
computed: {
attrMerge() {
return Object.assign({},
{
scrollEvents: ['scroll']
},
this.$attrs,
);
},
listenerMerge() {
return Object.assign({},
this.$listeners,
{
scroll: this.onScroll.bind(this)
}
);
}
},
methods: {
onScroll(pos) {
if (this.lottieBefore && this.$refs.scroll.pullDownRefresh) {
if (this.$refs.scroll.beforePullDown) {
if (pos.y > 43) {
this.lottieBefore.goToAndStop(Math.abs(pos.y - 43) * 15);
}
} else {
this.lottieBefore.goToAndStop(0);
}
}
this.$emit('scroll', pos);
},
forceUpdate(dirty) {
this.$refs.scroll.forceUpdate(dirty);
},
_initLottie() {
import(/* webpackChunkName: "lottie-web" */ 'lottie-web').then(lottie => {
this.lottieBefore = lottie.loadAnimation({
container: document.getElementById('beforePullDown'), // the dom element that will contain the animation
renderer: 'svg',
loop: false,
autoplay: false,
path: 'https://cdn.yoho.cn/mapp/lottie/ufo-pull-1227.json' // the path to the animation json
});
this.lottieAfter = lottie.loadAnimation({
container: document.getElementById('afterPullDown'), // the dom element that will contain the animation
renderer: 'svg',
loop: true,
autoplay: true,
path: 'https://cdn.yoho.cn/mapp/lottie/ufo-refresh-1227.json' // the path to the animation json
});
});
}
},
components: {Scroll}
};
</script>
<style lang="scss" scoped>
.scroll-view {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
overflow: hidden;
background: #fff;
}
.pulldown-wrapper {
position: absolute;
width: 100%;
left: 0;
top: -200px;
display: flex;
justify-content: center;
align-items: center;
transition: all;
.pulldown-content {
padding-left: 60px;
padding-right: 60px;
width: 100%;
height: 168px;
}
}
</style>