Skip to content

Commit b3229b1

Browse files
committed
[fix] Fixed new Slider value sync issue.
1 parent dc5cbe2 commit b3229b1

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

packages/Slider/src/index.vue

+15-17
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,10 @@ export default {
136136
this.$emit('change', val);
137137
},
138138
finalLeft() {
139-
if (!this.vertical) {
140-
let ratio =
141-
this.finalLeft / (this.barEl.width - this.btnEl.width);
142-
ratio = ratio * (this.maxinum - this.mininum) + this.mininum;
143-
if (this.moveable) {
144-
this.progress = ratio.toFixed(0);
145-
}
146-
}
139+
if (this.moveable) this.progress = this.setProgress();
147140
},
148141
finalTop() {
149-
if (!this.barEl.height || !this.btnEl.height) return;
150-
if (this.vertical) {
151-
let ratio =
152-
this.finalTop / (this.barEl.height - this.btnEl.height);
153-
ratio = ratio * (this.maxinum - this.mininum) + this.mininum;
154-
if (this.moveable) {
155-
this.progress = ratio.toFixed(0);
156-
}
157-
}
142+
if (this.moveable) this.progress = this.setProgress(true);
158143
}
159144
},
160145
computed: {
@@ -304,6 +289,7 @@ export default {
304289
this.currentLeft =
305290
toRatio * (this.barEl.width - this.btnEl.width);
306291
}
292+
if (!this.vertical) this.progress = this.setProgress();
307293
break;
308294
}
309295
}
@@ -322,6 +308,7 @@ export default {
322308
this.currentTop =
323309
toRatio * (this.barEl.height - this.btnEl.height);
324310
}
311+
if (this.vertical) this.progress = this.setProgress(true);
325312
break;
326313
}
327314
}
@@ -352,6 +339,17 @@ export default {
352339
this.currentLeft =
353340
(this.progress / (this.maxinum - this.mininum)) *
354341
(this.barEl.width - this.btnEl.width);
342+
},
343+
setProgress(vertical = false) {
344+
if (!vertical) {
345+
let ratio =
346+
this.finalLeft / (this.barEl.width - this.btnEl.width);
347+
ratio = ratio * (this.maxinum - this.mininum) + this.mininum;
348+
return ratio.toFixed(0);
349+
}
350+
let ratio = this.finalTop / (this.barEl.height - this.btnEl.height);
351+
ratio = ratio * (this.maxinum - this.mininum) + this.mininum;
352+
return ratio.toFixed(0);
355353
}
356354
}
357355
};

0 commit comments

Comments
 (0)