-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (47 loc) · 2.19 KB
/
Copy pathscript.js
File metadata and controls
61 lines (47 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const imageComparison = function () {
const dragCircles = document.querySelectorAll('.comparison-scrollCircle');
const imageComparisonRoot = document.querySelector('.qubely-block-image-comparison');
const imageComparisonimages = document.querySelectorAll('.qubely-block-image-comparison img');
imageComparisonimages.forEach( function (eachImg) {
eachImg.style.width = imageComparisonRoot.offsetWidth + 'px';
});
dragCircles.forEach( function (dragCircle) {
const container = dragCircle.parentNode;
const resizeElement = container.querySelector('.comparison-resize-img');
dragCircle.addEventListener('mousedown', function mouseDownTrigger(event) {
// prevent right click mousedown event
if(event.which == 3 || event.which == 2) {
dragCircle.removeEventListener('mousedown', mouseDownTrigger);
return;
}
draging(dragCircle);
});
function moving() {
let pageX = event.pageX ? event.pageX : event.touches[0].clientX,
containerOffset = container.getBoundingClientRect().left,
containerWidth = container.offsetWidth,
movingValue = (pageX - containerOffset) / (containerWidth / 100);
if(movingValue < 5) movingValue = 5;
else if(movingValue > 95) movingValue = 95;
dragCircle.style.left = movingValue+'%';
resizeElement.style.width = movingValue+'%';
}
function dragRevoveFunc() {
container.removeEventListener('mousemove', moving);
}
function draging(dragCircle) {
container.addEventListener('mousemove', moving);
container.addEventListener('mouseup', dragRevoveFunc);
window.addEventListener('mouseup', dragRevoveFunc);
}
dragCircle.addEventListener('touchmove', moving);
}); // end of dragcircle foreach
};
if (
document.readyState === 'complete' ||
(document.readyState !== 'loading' && !document.documentElement.doScroll)
) {
imageComparison();
} else {
document.addEventListener('DOMContentLoaded', imageComparison);
}