You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.9 KiB
JavaScript
76 lines
1.9 KiB
JavaScript
5 years ago
|
function rafAsync() {
|
||
|
return new Promise(resolve => {
|
||
|
requestAnimationFrame(resolve); //faster than set time out
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
function checkElement(selector) {
|
||
|
if (document.querySelector(selector) === null) {
|
||
|
return rafAsync().then(() => checkElement(selector));
|
||
|
} else {
|
||
|
return Promise.resolve(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var slideIndex = 1;
|
||
|
|
||
|
|
||
|
// Next/previous controls
|
||
5 years ago
|
function plusSlides(n, className = "mySlides") {
|
||
|
console.log("changing slides");
|
||
|
showSlides(slideIndex += n, className);
|
||
5 years ago
|
}
|
||
|
|
||
|
// Thumbnail image controls
|
||
5 years ago
|
function currentSlide(n, className = "mySlides") {
|
||
|
showSlides(slideIndex = n, className);
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
function showSlides(n, className = "mySlides") {
|
||
5 years ago
|
var i;
|
||
5 years ago
|
var slides = document.getElementsByClassName(className);
|
||
5 years ago
|
var dots = document.getElementsByClassName("dot");
|
||
|
if (n > slides.length) {slideIndex = 1}
|
||
|
if (n < 1) {slideIndex = slides.length}
|
||
|
for (i = 0; i < slides.length; i++) {
|
||
|
slides[i].style.display = "none";
|
||
|
}
|
||
|
for (i = 0; i < dots.length; i++) {
|
||
|
dots[i].className = dots[i].className.replace(" carousel-active", "");
|
||
|
}
|
||
|
slides[slideIndex-1].style.display = "block";
|
||
|
dots[slideIndex-1].className += " carousel-active";
|
||
|
}
|
||
|
|
||
|
checkElement('.mySlides') //use whichever selector you want
|
||
|
.then((element) => {
|
||
|
console.log("sldaldsaldsa");
|
||
|
showSlides(slideIndex);
|
||
|
});
|
||
5 years ago
|
|
||
|
checkElement('.mySlides2') //use whichever selector you want
|
||
|
.then((element) => {
|
||
|
console.log("sldaldsaldsa");
|
||
|
showSlides(slideIndex, "mySlides2");
|
||
|
});
|
||
|
|
||
|
checkElement('.mySlides3') //use whichever selector you want
|
||
|
.then((element) => {
|
||
|
console.log("sldaldsaldsa");
|
||
|
showSlides(slideIndex, "mySlides3");
|
||
|
});
|
||
|
|
||
|
checkElement('.mySlides4') //use whichever selector you want
|
||
|
.then((element) => {
|
||
|
console.log("sldaldsaldsa");
|
||
|
showSlides(slideIndex, "mySlides4");
|
||
|
});
|
||
|
|
||
|
checkElement('.mySlides5') //use whichever selector you want
|
||
|
.then((element) => {
|
||
|
console.log("sldaldsaldsa");
|
||
|
showSlides(slideIndex, "mySlides5");
|
||
|
});
|
||
|
|