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