forked from mescroll/mescroll
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmescroll.vue
127 lines (125 loc) · 2.51 KB
/
mescroll.vue
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
117
118
119
120
121
122
123
124
125
126
127
/*
* mescroll 滚动
* @Author: liangzc
* @Date: 2018-03-13 09:59:44
* @Last Modified by: liangzc
* @Last Modified time: 2018-03-13 14:07:58
*/
<template>
<div :id="id"
class="mescroll"
ref="mescroll">
<span>
<slot/>
</span>
</div>
</template>
<script type="text/babel">
export default {
name: 'me-scroll',
props: {
/**
* 滚动区域Id
*/
id: {
type: String,
default: 'mescroll'
},
/**
* 下拉参数
*/
optDown: {
type: Object,
default: () => {}
},
/**
* 下拉回调
*/
downCallback: {
type: Function
},
/**
* 上拉参数
*/
optUp: {
type: Object,
default: () => {}
},
/**
* 上拉回调
*/
upCallback: {
type: Function
},
/**
* 统一回调
*/
callback: {
type: Function
}
},
data() {
return {
instance: null
};
},
mounted() {
if (!window._Mescroll) {
require('./mescroll.min.css');
window._Mescroll = require('./mescroll.min.js');
}
if (!this.downCallback && !this.upCallback && this.callback) {
if (!this.isEmptyObject(this.upOption)) {
this.upOption.callback = this.callback;
this.downOption.use = false;
} else if (!this.isEmptyObject(this.downOption)) {
this.downOption.callback = this.callback;
this.upOption.use = false;
}
}
this.upOption.auto = !(this.downOption.callback && this.upOption.callback);
this.instance = new window._Mescroll(this.id, {
down: this.downOption,
up: this.upOption
});
},
computed: {
upOption() {
let optUp = this.optUp || {};
optUp.isBounce =
typeof optUp.isBounce !== 'undefined' ? optUp.isBounce : false;
optUp.callback =
typeof optUp.callback !== 'undefined' ?
optUp.callback :
this.upCallback;
let empty = optUp.empty || {};
empty.warpId =
typeof empty.warpId !== 'undefined' ? empty.warpId : this.id;
optUp.empty = empty;
return optUp;
},
downOption() {
let optDown = this.optDown || {};
optDown.callback =
typeof optDown.callback !== 'undefined' ?
optDown.callback :
this.downCallback;
return optDown;
}
},
methods: {
isEmptyObject(obj) {
let name;
for (name in obj) {
return false;
}
return true;
}
}
};
</script>
<style lang="scss">
.mescroll {
position: fixed;
}
</style>