pedf
/
spolky
Archived
1
0
Fork 0
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

75 lines
2.0 KiB
JavaScript

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;
var slideIndex2 = 1;
var slideIndex3 = 1;
function stop_vids() {
for (var video of document.querySelectorAll("video")) {
video.pause();
}
}
// Next/previous controls
function plusSlides(n, className = "mySlides", counter = "slideIndex", dotclass = "dot") {
console.log("changing slides");
showSlides(window[counter] += n, className, counter, dotclass);
stop_vids();
}
// Thumbnail image controls
function currentSlide(n, className = "mySlides", counter = "slideIndex", dotclass = "dot") {
showSlides(window[counter] = n, className, counter, dotclass);
stop_vids()
}
function showSlides(n, className = "mySlides", counter = "slideIndex", dotclass = "dot") {
var i;
var slides = document.getElementsByClassName(className);
var dots = document.getElementsByClassName(dotclass);
if (n > slides.length) {window[counter] = 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[window[counter]-1].style.display = "block";
dots[window[counter]-1].className += " carousel-active";
}
checkElement('.mySlides') //use whichever selector you want
.then((element) => {
console.log("sldaldsaldsa");
showSlides(slideIndex);
});
checkElement('.mySlides2') //use whichever selector you want
.then((element) => {
console.log("sldaldsaldsa");
showSlides(slideIndex2, "mySlides2", "slideIndex2");
});
checkElement('.mySlides3') //use whichever selector you want
.then((element) => {
console.log("sldaldsaldsa");
showSlides(slideIndex3, "mySlides3", "slideIndex3");
});