-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
87 lines (74 loc) · 2.1 KB
/
script.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
75
76
77
78
79
80
81
82
83
84
85
86
87
const sliderItems = document.querySelectorAll(".slider-item");
const sliderLine = document.querySelector(".slider-line");
let count = 0;
let width;
function init() {
console.log("resize");
width = document.querySelector(".slider").offsetWidth;
sliderLine.style.width = width* sliderItems.length + "px";
sliderItems.forEach(item =>
{item.style.width = width + "px";
item.style.height = "auto";
});
rollSlider();
}
window.addEventListener("resize", init);
init();
document.querySelector(".slider-next").addEventListener("click", function(){
count++;
if (count >= sliderItems.length){
count = 0;
}
rollSlider();
});
document.querySelector(".slider-prev").addEventListener("click", function(){
count--;
if (count < 0){
count = sliderItems.length - 1;
}
rollSlider();
});
function rollSlider(){
sliderLine.style.transform = "translate(-" + count*width + "px)";
}
function burgerFunc() {
var x = document.getElementById("myLinks");
if (x.style.display === "block") {
x.style.height = "0";
x.style.display = "none";
} else {
x.style.display = "block";
x.style.height = "fit-content";
}
}
/*document.addEventListener("touchstart", handleTouchStart, false);
document.addEventListener("touchmove", handleTouchMove, false);
const logBlock = document.querySelector(".slider")
let x1 = null;
let y1 = null;
function handleTouchStart(event){
const firstTouch = event.touches[0]
x1 = firstTouch.clientX;
y1 = firstTouch.clientY;
console.log(x1, y1);
}
function handleTouchMove(event){
if (!x1 || !y1){
return false;
}
let x2 = event.touches[0].clientX;
let y2 = event.touches[0].clientY;
console.log(x2, y2);
let xDif = x2 - x1;
let yDif = y2 - y1;
if(Math.abs(xDif)> Math.abs(yDif)){
if (xDif > 0) logBlock("right");
else console.log("left");
}
else{
if (yDif > 0) console.log("down");
else console.log("up");
}
x1 = null;
y1 = null;
} */