-
Notifications
You must be signed in to change notification settings - Fork 0
/
section4.js
119 lines (104 loc) · 4.88 KB
/
section4.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
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
let OtherProjects = new AutoType({
parent: document.getElementById("Otherprojects"),
writeSpeed: 50,
deleteSpeed: 200,
opacityTransition: 0.2,
className: ["rotHover"]
})
.Write("Other projects")
let OtherProjectsWritten = false
function StartSection4() {
if (!OtherProjectsWritten) {
OtherProjectsWritten = true;
OtherProjects.Start()
}
}
function StopSection4() {}
function carrousel(id, list, toRight) {
this.array = []
this.timeCarrousel = 0;
this.imgesSizeCarrousel = 200;
this.imageMargeCarrousel = 20;
this.nombreImageCarrousel = 0;
this.speedCarrousel = toRight ? this.imgesSizeCarrousel + this.imageMargeCarrousel : -this.imgesSizeCarrousel - this.imageMargeCarrousel;
this.slideImagesInterval;
this.id = id;
this.list = list;
this.time2translate = 4000;
this.transitionValue = ["all " + this.time2translate / 1000 + "s linear", "all " + this.time2translate / 1000 + "s cubic-bezier(0.25, 0.1, 0.25, 1)"];
this.mode = 0 //l linear, b bezier
this.generate = function () {
let container = document.getElementById(this.id);
let counter = 0
this.list.forEach(project => {
let a = document.createElement('a');
a.href = project.action;
a.target = '_blank';
let holdImg = document.createElement('div');
holdImg.style.width = `${this.imgesSizeCarrousel}px`
holdImg.style.height = `${this.imgesSizeCarrousel}px`
let img = document.createElement('img');
img.src = project.source;
img.style.width = `${this.imgesSizeCarrousel}px`
img.style.height = `${this.imgesSizeCarrousel}px`
holdImg.classList.add("holdImg-carrousel")
img.classList.add("img-carrousel")
container.appendChild(a);
a.appendChild(holdImg);
holdImg.appendChild(img);
let margeLeft = counter * (this.imageMargeCarrousel + this.imgesSizeCarrousel)
holdImg.style.marginLeft = `${margeLeft}px`
this.array.push([holdImg, counter]);
counter++;
})
this.nombreImageCarrousel = counter;
container.style.maxWidth = `${(this.nombreImageCarrousel-2)*(this.imgesSizeCarrousel + this.imageMargeCarrousel)}px`
container.style.height = `${this.imgesSizeCarrousel}px`
container.addEventListener("mouseenter", () => {
this.pause = true;
});
container.addEventListener("mouseleave", () => {
this.pause = false;
});
this.slideImages(this)
this.slideImagesInterval = setInterval(this.slideImages, this.time2translate, this);
}
this.slideImages = function (obj) {
if (!obj.pause) {
obj.array.forEach(element => {
if (obj.speedCarrousel > 0) {
let margeLeft = (element[1] * (obj.imageMargeCarrousel + obj.imgesSizeCarrousel) + obj.timeCarrousel * obj.speedCarrousel) % ((obj.nombreImageCarrousel) * (obj.imageMargeCarrousel + obj.imgesSizeCarrousel))
if (margeLeft <= 0) {
element[0].style.transition = "none"
element[0].style.marginLeft = `${-(obj.imageMargeCarrousel + obj.imgesSizeCarrousel)}px`
} else {
element[0].style.transition = obj.transitionValue[obj.mode]
element[0].style.marginLeft = `${margeLeft -(obj.imageMargeCarrousel + obj.imgesSizeCarrousel)}px`
}
} else {
let margeLeft = (element[1] * (obj.imageMargeCarrousel + obj.imgesSizeCarrousel) - obj.timeCarrousel * obj.speedCarrousel) % ((obj.nombreImageCarrousel) * (obj.imageMargeCarrousel + obj.imgesSizeCarrousel))
if (margeLeft <= 0) {
element[0].style.transition = "none"
element[0].style.marginLeft = `${(obj.nombreImageCarrousel - 3) * (obj.imageMargeCarrousel + obj.imgesSizeCarrousel)+(obj.imageMargeCarrousel + obj.imgesSizeCarrousel)}px`
} else {
element[0].style.transition = obj.transitionValue[obj.mode]
element[0].style.marginLeft = `${(obj.nombreImageCarrousel - 3) * (obj.imageMargeCarrousel + obj.imgesSizeCarrousel) - margeLeft + (obj.imageMargeCarrousel + obj.imgesSizeCarrousel)}px`
}
}
})
obj.timeCarrousel++;
}
}
}
var carrousel1 = new carrousel('carrouselImages1', imagesCards1, true);
var carrousel2 = new carrousel('carrouselImages2', imagesCards2, false);
var carrousel3 = new carrousel('carrouselImages3', imagesCards3, true);
setTimeout(function () {
carrousel1.generate()
}, 0);
setTimeout(function () {
carrousel3.generate()
}, 0);
setTimeout(function () {
carrousel2.generate()
}, 0);