Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

allow changing percentage via prop #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/VueCompareImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down