|
Server : Apache System : Linux s1230 5.15.0-139-generic #149~20.04.1 SMP Tue Jul 14 11:21:49 UTC 2026 x86_64 User : p141464 ( 418825) PHP Version : 7.4.33.12 Disable Function : NONE Directory : /html/relaunch-kmu/wp-content/plugins/wp-gdpr-compliance/Resources/js/admin/ |
Upload File : |
/**
* Comparison slider
*/
export default class ComparisonSlider {
constructor () {
this.setProperties()
this.init()
}
setProperties () {
this.slider = document.querySelector('.wpgdprc-comparison-slider')
this.topSlide = document.querySelector('.wpgdprc-comparison-slider__top')
this.line = document.querySelector('.wpgdprc-comparison-slider__line')
}
init () {
if (!this.slider) return
this.setInitialPosition()
this.slider.addEventListener('mousemove', (e) => {
const rect = this.slider.getBoundingClientRect()
const x = e.clientX - rect.left
this.setOffsets(x)
})
window.addEventListener('resize', () => {
this.setInitialPosition()
})
}
setOffsets (x) {
this.topSlide.style.clip = `rect(auto, ${x}px, auto, auto)`
let offset = x - this.line.getBoundingClientRect().width / 2
if (offset < 0) {
offset = 0
}
const maxWidth = this.topSlide.getBoundingClientRect().width
if (offset > maxWidth) {
offset = maxWidth
}
this.line.style.left = `${offset >= 0 ? offset : 0}px`
}
setInitialPosition () {
this.setOffsets(this.slider.getBoundingClientRect().width / 2)
}
}