goodsSwiper.js
2.34 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
117
118
119
120
Component({
properties: {
data: {
type: Array,
observer(n) {
if (n && n.length) {
this.setData({
list: n
})
this.startSwiper()
}
}
},
conType:Number
},
/**
* 组件的初始数据
*/
data: {
list: [],
},
/**
* 组件的方法列表
*/
methods: {
fulfill() {
if (this.timer) clearTimeout(this.timer)
this.timer = setTimeout(() => {
let {
list
} = this.data
list.splice(0, 1)
this.setData({
animation: false
}, () => {
wx.nextTick(() => {
this.setData({
list,
zoom: false
})
})
})
}, 400)
},
clickGoods(auto) {
let {
animation,
list
} = this.data,
[item] = list
if (animation) return
this.stop = auto == true ? false : true
list.push(item)
this.setData({
animation: true,
list
}, () => {
setTimeout(() => {
this.setData({
zoom: true
})
this.fulfill()
if (this.stop) {
this.stop = false
this.startSwiper()
}
}, 200)
})
},
startSwiper() {
if (this.swiperTimer) clearTimeout(this.swiperTimer)
this.swiperTimer = setTimeout(() => {
if (this.stop) {
return clearTimeout(this.swiperTimer)
}
this.clickGoods(true)
this.startSwiper()
}, 3e3)
},
start(e) {
let cell = e.changedTouches[0]
this.startX = cell.clientX
this.startY = cell.clientY
},
// move(e) {
// let {
// startX,
// startY,
// data: {
// list
// }
// } = this
// let {
// index
// } = e.currentTarget.dataset
// let {
// clientX,
// clientY
// } = e.changedTouches[0]
// let X = clientX - startX
// let Y = clientY - startY
// let angle = (360 * Math.atan(Y / X)) / (2 * Math.PI)
// let result = clientX < startX
// if (Math.abs(angle) > 30) return
// if (!result) return
// list[index].style = `transform: translateX(-${startX - clientX}px)`
// this.setData({
// list
// })
// }
}
})