-
Notifications
You must be signed in to change notification settings - Fork 0
/
slider.js
85 lines (67 loc) · 2.35 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
75
76
77
78
79
80
81
82
83
84
85
var controls = document.querySelectorAll('.controls');
for(var i=0; i < controls.length; i++){
controls[i].style.display = 'inline-block';
}
var slides = document.querySelectorAll('#slides .slide');
var currentSlide = 0;
var slideInterval = setInterval(nextSlide,5000);
function nextSlide() {
goToNextSlide();
}
function previousSlide() {
goToSlide(currentSlide-1);
}
var playing = true;
var pauseButton = document.getElementById('pause');
function pauseSlideshow() {
pauseButton.innerHTML = '►';
playing = false;
clearInterval(slideInterval);
}
function playSlideshow() {
pauseButton.innerHTML = '❚❚';
playing = true;
slideInterval = setInterval(nextSlide,5000);
}
pauseButton.onclick = function() {
if(playing){ pauseSlideshow(); }
else{ playSlideshow(); }
};
var next = document.getElementById('next');
var previous = document.getElementById('previous');
function goToNextSlide(e) {
console.log(e)
const container = $('#slides');
const currentSlide = $(".slide.showing");
const prevSlide = $(slides[currentSlide.index() - 1]);
const nextSlide = $(slides[currentSlide.index() + 1]);
currentSlide.animate({"left": -currentSlide.outerWidth()}, "fast", complete => {
currentSlide.css('left', '100%');
});
nextSlide.animate({"left": 0}, "fast", complete => {
nextSlide.css('left', '0');
});
currentSlide.removeClass('showing');
nextSlide.addClass('showing');
container[0].appendChild(prevSlide[0]);
slides = document.querySelectorAll('#slides .slide');
}
function goToPrevSlide() {
const container = $('#slides');
const currentSlide = $(".slide.showing");
const prevSlide = $(slides[currentSlide.index() - 1]);
const lastSlide = $(slides[slides.length - 1]);
currentSlide.animate({"left": currentSlide.outerWidth()}, "fast", complete => {
currentSlide.css('left', '100%');
});
prevSlide.css('left', '-100%');
prevSlide.animate({"left": 0}, "fast", complete => {
prevSlide.css('left', '0');
});
currentSlide.removeClass('showing');
prevSlide.addClass('showing');
container[0].prepend(lastSlide[0]);
slides = document.querySelectorAll('#slides .slide');
}
$("#next").on('click', goToNextSlide);
$("#previous").on('click', goToPrevSlide);