From d35618575fc3b1ca99529d679a0e5b5facaf5fd5 Mon Sep 17 00:00:00 2001 From: DRC Date: Tue, 16 Mar 2021 14:20:28 +0100 Subject: [PATCH] allow changing percentage via prop --- src/VueCompareImage.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/VueCompareImage.vue b/src/VueCompareImage.vue index 26c7132..f8857d0 100644 --- a/src/VueCompareImage.vue +++ b/src/VueCompareImage.vue @@ -135,24 +135,26 @@ export default Vue.extend({ const imagePosition = this.$refs.rightImageRef.getBoundingClientRect(); let pos = cursorXfromWindow - imagePosition.left; - // Set minimum and maximum values ​​to prevent the slider from overflowing + // Set minimum and maximum values to prevent the slider from overflowing const minPos = 0 + this.sliderLineWidth / 2; const maxPos = this.imageWidth - this.sliderLineWidth / 2; if (pos < minPos) pos = minPos; if (pos > maxPos) pos = maxPos; - this.positionPct = pos / this.imageWidth; + this.sliderPositionPercentage = pos / this.imageWidth; }, }, data() { return { // slider position percentage(0 to 1) - positionPct: this.sliderPositionPercentage || 0.5, imageWidth: 0, }; }, computed: { + positionPct () { + return this.sliderPositionPercentage + }, // eslint-disable leftImageStyle() { return {