-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlideCard.wpy
55 lines (51 loc) · 1.17 KB
/
SlideCard.wpy
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
<template>
<view class="weslide-card" @touchstart="touchStart" @touchend="touchEnd">
<view class="weconstant-side" style="flex: {{constantFlex}}">
<slot name="constant-content"></slot>
</view>
<view class="weslide-side" style="flex: {{$_slideFlex}}">
<slot name="slide-content"></slot>
</view>
</view>
</template>
<script>
import wepy from 'wepy'
export default class extends wepy.component {
data = {
$_slideFlex: 0,
touchStartClientX: 0,
touchEndClientX: 0
}
props = {
constantFlex: Number,
slideFlex: Number
}
methods = {
touchStart(e) {
this.touchStartClientX = e.touches[0] ? e.touches[0].clientX : 0
},
touchEnd(e) {
this.touchEndClientX = e.changedTouches[0]
? e.changedTouches[0].clientX
: 0
const offsetX =
Number(this.touchStartClientX) - Number(this.touchEndClientX)
if (offsetX > 30) {
this.$_slideFlex = this.slideFlex
} else if (-offsetX > 30) {
this.$_slideFlex = 0
}
}
}
}
</script>
<style scoped>
.weslide-card {
display: flex;
width: 100%;
}
.weslide-side {
transition: all 0.5s;
overflow: hidden;
}
</style>