-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.js
74 lines (58 loc) · 1.72 KB
/
slider.js
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
let move = 0;
let number;
//let wrapper = document.createElement('div');
//wrapper.classList.add('wrapper');
temp = 0;
width = wrapper.clientWidth;
document.addEventListener('DOMContentLoaded', function() {
let slide = document.querySelector('*[data-slide]');
if (!slide) return;
number = slide.getAttribute('data-slide');
// Задел на будущее...
});
wrapper.onmousedown = function(event) {
let beginCoords = event.clientX;
document.querySelector('.slider').style.transition = "0s all";
wrapper.onmousemove = function(event) {
let moveCoords = beginCoords - event.clientX;
difference = -moveCoords + temp;
//document.querySelector('.coords').textContent = 'X : ' + event.clientX + ' Y : ' + event.clientY;
CheckAndTranslate();
}
function newCoords() {
koef = difference/width;
difference = Math.round(koef) * width;
};
function criterion() {
if (difference > 0 || difference < -width*9) {
if (difference > 0) {
difference = 0;
}
if (difference < -width*9) {
difference = -width*9;
}
}
};
function translate() {
document.querySelector('.slider').style.transform = 'translateX(' + difference + 'px)';
};
function CheckAndTranslate() {
criterion();
translate();
};
document.onmouseup = function() {
wrapper.onmousemove = document.onmouseup = null;
newCoords();
temp = difference;
document.querySelector('.slider').style.transition = "0.5s all";
translate();
}
return false;
};
document.ondragstart = function() {
return false;
};
function interval() {
document.querySelector('.slider').style.transition = "0.5s all";
setInterval(moving, 3000);
};