forked from juliacheperis13/Double_slider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
162 lines (133 loc) · 3.32 KB
/
index.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> JS </title>
<style>
#holder{
display: block;
position: relative;
overflow: hidden;
height: 450px;
width: 100vw;
height: 100vh;
/*width: 100%;*/
background-color: lightblue;
/*margin: 0 auto;*/
z-index: 1;
box-sizing: border-box;
}
#left{
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 100%;
z-index: 25;
/*background-color: lightgreen;*/
background-image: url("./images/img_bcg.jpg");
background-repeat: no-repeat;
background-size: 100vw 100vh, cover;
filter: contrast(130%);
box-sizing: border-box;
}
#right{
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
z-index: 20;
/*background-color: pink;*/
background-image: url("./images/img_bcg.jpg");
filter: grayscale(100%);
background-repeat: no-repeat;
background-size: 100vw 100vh, cover;
box-sizing: border-box;
}
#mover{
position: relative;
height: 100%;
z-index: 30;
width: 8px;
background-color: #4db8ff;
top: 0;
left: calc(50% - 2.5px);
cursor: grabbing;
}
#mover:before {
content: '';
position: absolute;
height: 179px;
width: 179px;
border-radius: 50%;
background-image: url('./images/img_compass.jpg');;
top: 65vh;
left: -86px;
background-size: 202%;
background-position: center;
}
.animated:before{
animation: round linear 5s infinite;
}
@keyframes round{
0%{
transform: rotate(0deg);
}
100%{
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div id='holder'>
<div id='mover'></div>
<div id='left'></div>
<div id='right'></div>
</div>
<script type="text/javascript">
var mover = document.getElementById('mover');
var holder = document.getElementById('holder');
var leftSection = document.getElementById('left');
mover.onmousedown = function(e) {
var thumbCoords = getCoords(mover);
var shiftX = e.pageX - thumbCoords.left;
// shiftY здесь не нужен, слайдер двигается только по горизонтали
var sliderCoords = getCoords(holder);
document.onmousemove = function(e) {
// вычесть координату родителя, т.к. position: relative
var newLeft = e.pageX - shiftX - sliderCoords.left;
// курсор ушёл вне слайдера
if (newLeft < 0) {
newLeft = 0;
}
var rightEdge = holder.offsetWidth - mover.offsetWidth;
if (newLeft > rightEdge) {
newLeft = rightEdge;
}
mover.style.left = newLeft + 'px';
mover.classList.add('animated');
console.log(newLeft);
// leftSection.style.width = (newLeft + 'px') - (mover.style.width + 'px');
leftSection.style.width = newLeft + 'px';
}
document.onmouseup = function() {
document.onmousemove = document.onmouseup = null;
mover.classList.remove('animated');
};
return false; // disable selection start (cursor change)
};
mover.ondragstart = function() {
return false;
};
function getCoords(elem) { // кроме IE8-
var box = elem.getBoundingClientRect();
return {
// top: box.top + pageYOffset,
left: box.left + pageXOffset
};
}
</script>
</body>
</html>