Skip to content
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
28 changes: 14 additions & 14 deletions src/cato.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,29 @@ export default class Cato {

setStyles(range, {
top: imgBase.getBoundingClientRect().height / 2 + 'px',
width: imgBase.width + 'px',
width: imgBase.getBoundingClientRect().width + 'px',
})

range.value = this.options.initial

// initial overlap
const initialClip =
this.options.direction === 'horizontal'
? (imgBase.width * this.options.initial) / 100
? (imgBase.getBoundingClientRect().width * this.options.initial) / 100
: (imgBase.height * this.options.initial) / 100
setVendor(imgBase, "ClipPath", setInsetDirection(
this.options.direction,
initialClip,
))

setVendor(imgBase, "ClipPath", setInsetDirection(
this.options.direction,
initialClip,
))

// flip input range and adjust to the side if vertical
if (this.options.direction === 'vertical') {
setStyles(range, {
transform: 'rotate(90deg)',
transformOrigin: 'left', // use left edge for transformation instead of center
width: imgBase.getBoundingClientRect().height + 'px', // set width to height, because the indicator is rotated for 90°
left: imgBase.width / 2 + 'px', // center it horizontally
left: imgBase.getBoundingClientRect().width / 2 + 'px', // center it horizontally
top: 0,
marginTop: '-2px',
})
Expand All @@ -95,7 +95,7 @@ export default class Cato {
if (this.options.direction === 'vertical') {
setStyles(this.range, {
width: this.imgBase.getBoundingClientRect().height + 'px', // set width to height, because the indicator is rotated for 90°
left: this.imgBase.width / 2 + 'px', // center it horizontally
left: this.imgBase.getBoundingClientRect().width / 2 + 'px', // center it horizontally
})
} else {
setStyles(this.range, {
Expand All @@ -107,17 +107,17 @@ export default class Cato {
}

handleSlides() {
const width = this.imgBase.width
const width = this.imgBase.getBoundingClientRect().width
const height = this.imgBase.getBoundingClientRect().height
const slidedWith =
this.options.direction === 'horizontal'
? (width * this.range.value) / 100
: (height * this.range.value) / 100

setVendor(this.imgBase, "ClipPath", setInsetDirection(
this.options.direction,
slidedWith,
))
setVendor(this.imgBase, "ClipPath", setInsetDirection(
this.options.direction,
slidedWith,
))
this.resizeIndicator()
return false
}
Expand Down