-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslideshow.js
executable file
·106 lines (83 loc) · 2.5 KB
/
slideshow.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
/*
SLIDESHOW 0.01;
*/
var slides;
function loadSlideshow(name){
slides = document.getElementsByClassName("slide")
var marge = 10
var width = document.getElementById(name).offsetWidth + marge
for (var i = 1; i < slides.length; i++) {
slides[i].style.left = i*width + "px"
// par rapport à la precedente taille d'image
// console.log(i);
// slides[i].style.left = slides[i-1].childNodes[1].width + slides[i-1].offsetLeft + "px"
// console.log("offset "+slides[i].offsetLeft);
}
// console.log(document.getElementById("slides").scrollLeft);
// setTimeout(function() { document.getElementById("slides").scrollLeft = 0; }, 1);
}
var posSlide = 0;
function previous(){
previous(30);
}
function previous(speed){
if (posSlide > 0){
posSlide --;
}else{
posSlide = 0
}
moveTo("slide"+posSlide,speed);
}
function next(){
next(30)
}
function next(speed){
if (posSlide < slides.length-1){
posSlide ++;
}else{
posSlide = slides.length-1
}
moveTo("slide"+posSlide,speed);
}
function jumpToSlide(num){
var target = document.getElementById("slide"+num).offsetLeft
// console.log(num)
// console.log(target)
// document.getElementById("slides").scrollLeft = target
// console.log(document.getElementById("slides").scrollLeft);
document.getElementById("slides").scrollLeft = target
}
function jumpTo(anchor){
var target = document.getElementById(anchor).offsetLeft
// console.log(anchor+" "+target);
// document.getElementById("slides").scroll({
// top: 0,
// left: target,
// behavior: 'smooth'
// });
document.getElementById("slides").scrollLeft = target
// document.getElementById("slides").scrollTo(0,target);
// window.location.href = "#"+anchor;
/*
*/
}
function moveTo(anchor, speed){
var target = document.getElementById(anchor).offsetLeft
//document.getElementById("slides").scrollLeft = target
var id = setInterval(frame, 10)
// console.log("target ="+target);
// console.log("position ="+document.getElementById("slides").scrollLeft);
function frame(){
// console.log("y ="+document.getElementById("slides").scrollLeft);
if(document.getElementById("slides").scrollLeft + speed < target){
document.getElementById("slides").scrollLeft += speed
}else if(document.getElementById("slides").scrollLeft - speed > target){
document.getElementById("slides").scrollLeft -= speed
}else{
document.getElementById("slides").scrollLeft = target
}
if(document.getElementById("slides").scrollLeft == target){
clearInterval(id);
}
}
}