Skip to content

Commit 18d5050

Browse files
committed
根据PR建议做调整, 增加scoped和抽离出函数
1 parent fc7b144 commit 18d5050

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

example/pages/cell-swipe.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
};
3434
</script>
3535

36-
<style>
36+
<style scoped>
3737
.page-cell{
3838
height: 130vh;
3939
}

packages/cell-swipe/src/cell-swipe.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ export default {
126126
return `translate3d(${offset}px, 0, 0)`;
127127
},
128128
129+
setAnimations(on) {
130+
var val = on ? null : '0ms';
131+
this.wrap.style.transitionDuration = val;
132+
this.rightWrapElm.style.transitionDuration = val;
133+
this.leftWrapElm.style.transitionDuration = val;
134+
},
135+
129136
swipeMove(offset = 0) {
130137
this.wrap.style.webkitTransform = this.translate3d(offset);
131138
this.rightWrapElm.style.webkitTransform = this.translate3d(this.rightWidth + offset);
@@ -172,9 +179,7 @@ export default {
172179
if (this.opened) {
173180
if (!this.swiping) {
174181
this.swipeMove(0);
175-
this.wrap.style.transitionDuration = null;
176-
this.rightWrapElm.style.transitionDuration = null;
177-
this.leftWrapElm.style.transitionDuration = null;
182+
this.setAnimations(true);
178183
}
179184
this.opened = false;
180185
return;
@@ -189,9 +194,7 @@ export default {
189194
const y = Math.abs(offsetTop);
190195
const x = Math.abs(offsetLeft);
191196
192-
this.wrap.style.transitionDuration = '0ms';
193-
this.rightWrapElm.style.transitionDuration = '0ms';
194-
this.leftWrapElm.style.transitionDuration = '0ms';
197+
this.setAnimations(false);
195198
196199
if (this.direction === null) {
197200
this.direction = x > y ? 'horizonal' : 'vertical';
@@ -216,9 +219,7 @@ export default {
216219
217220
endDrag() {
218221
this.direction = null;
219-
this.wrap.style.transitionDuration = null;
220-
this.rightWrapElm.style.transitionDuration = null;
221-
this.leftWrapElm.style.transitionDuration = null;
222+
this.setAnimations(true);
222223
if (!this.swiping) return;
223224
this.swipeLeaveTransition(this.offsetLeft > 0 ? -1 : 1);
224225
}

0 commit comments

Comments
 (0)