Trying to make a slideshow gallery with autoplay and controls (select, pause, next, previous..).
- January 20, 2022
- 5 replies
- 2888 views
Not sure I have the correct terms here, so here is a picture of a type of gallery which appeals to me - Mostly because it's simple and functional.

It's essentially the gallery that is described in W3 Schools at...
https://www.w3schools.com/howto/howto_js_slideshow_gallery.asp
But I would like to have this gallery autoplaying (like a slider) when the page opens while giving the reader the option of taking control to pause and select slides by the thumbnails or arrows.
Here is the HTML and JS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="d:/webs/helenavista/helenavista P12/css/global.css"
rel="stylesheet"
type="text/css"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<style></style>
</head>
<body>
<!-- BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB B O D Y BBBB -->
<!-- -->
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDESHOW-GALLERY 1 %%%%%%%%%%%%%% -->
<!-- -->
<hr class="thick" />
<h3>{GAL1} Gallery 1</h3>
<div class="gallery_1_container" style="width: 50%">
<!-- ------------------------ SLIDES-START -->
<div class="gallery_1_Slides">
<div class="gallery_1_numbertext">1 / 7</div>
<img
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_fish-marlin_2011-12-15_112401.jpg"
style="width: 100%"
/>
</div>
<div class="gallery_1_Slides">
<div class="gallery_1_numbertext">2 / 7</div>
<img
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_scenic-cristobal_2011-03-13_175353.jpg"
style="width: 100%"
/>
</div>
<div class="gallery_1_Slides">
<div class="gallery_1_numbertext">3 / 7</div>
<img
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_suites-1-ph_2014-03-25_065533_012.jpg"
style="width: 100%"
/>
</div>
<div class="gallery_1_Slides">
<div class="gallery_1_numbertext">4 / 7</div>
<img
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_fish-pc_2011-03-12_151934.jpg"
style="width: 100%"
/>
</div>
<div class="gallery_1_Slides">
<div class="gallery_1_numbertext">5 / 7</div>
<img
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_surf-carola_2018-12-21_072217_sc.jpg"
style="width: 100%"
/>
</div>
<div class="gallery_1_Slides">
<div class="gallery_1_numbertext">6 / 7</div>
<img
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_wl_2007-08-18_153437.jpg"
style="width: 100%"
/>
</div>
<div class="gallery_1_Slides">
<div class="gallery_1_numbertext">7 / 7</div>
<img
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_wl_2011-01-23_173030.jpg"
style="width: 100%"
/>
</div>
<!-- ------------------------ SLIDES-END -->
<a class="gallery_1_prev" onclick="gallery_1_plusSlides(-1)">❮</a>
<a class="gallery_1_next" onclick="gallery_1_plusSlides(1)">❯</a>
<!-- ------------------------ CAPTION -->
<div class="gallery_1_caption-container">
<p id="gallery_1_caption"></p>
</div>
<!-- ------------------------------- THUMBNAILS -->
<div class="gallery_1_row">
<div class="gallery_1_thumb" style="width: 14.28%">
<img
class="gallery_1_demo pointcursor"
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_fish-marlin_2011-12-15_112401.jpg"
style="width: 100%"
onclick="gallery_1_currentSlide(1)"
alt="Marlin"
/>
</div>
<div class="gallery_1_thumb" style="width: 14.28%">
<img
class="gallery_1_demo pointcursor"
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_scenic-cristobal_2011-03-13_175353.jpg"
style="width: 100%"
onclick="gallery_1_currentSlide(2)"
alt="Leon Dormido"
/>
</div>
<div class="gallery_1_thumb" style="width: 14.28%">
<img
class="gallery_1_demo pointcursor"
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_suites-1-ph_2014-03-25_065533_012.jpg"
style="width: 100%"
onclick="gallery_1_currentSlide(3)"
alt="Galeodan Penthouse Suite"
/>
</div>
<div class="gallery_1_thumb" style="width: 14.28%">
<img
class="gallery_1_demo pointcursor"
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_fish-pc_2011-03-12_151934.jpg"
style="width: 100%"
onclick="gallery_1_currentSlide(4)"
alt="Amberjack"
/>
</div>
<div class="gallery_1_thumb" style="width: 14.28%">
<img
class="gallery_1_demo pointcursor"
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_surf-carola_2018-12-21_072217_sc.jpg"
style="width: 100%"
onclick="gallery_1_currentSlide(5)"
alt="Carola Surf"
/>
</div>
<div class="gallery_1_thumb" style="width: 14.28%">
<img
class="gallery_1_demo pointcursor"
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_wl_2007-08-18_153437.jpg"
style="width: 100%"
onclick="gallery_1_currentSlide(6)"
alt="Tortoise"
/>
</div>
<div class="gallery_1_thumb" style="width: 14.28%">
<img
class="gallery_1_demo pointcursor"
src="http://www.helenavista.com/testgalleries/g1-home/carousel-g1-home_wl_2011-01-23_173030.jpg"
style="width: 100%"
onclick="gallery_1_currentSlide(7)"
alt="Blue Heron"
/>
</div>
</div>
</div>
<!-- ------------------------------- SCRIPT -->
<script>
var gallery_1_slideIndex = 1;
gallery_1_showSlides(gallery_1_slideIndex);
function gallery_1_plusSlides(n) {
gallery_1_showSlides((gallery_1_slideIndex += n));
}
function gallery_1_currentSlide(n) {
gallery_1_showSlides((gallery_1_slideIndex = n));
}
function gallery_1_showSlides(n) {
var i;
var slides =
document.getElementsByClassName("gallery_1_Slides");
var dots = document.getElementsByClassName("gallery_1_demo");
var gallery_1_captionText =
document.getElementById("gallery_1_caption");
if (n > slides.length) {
gallery_1_slideIndex = 1;
}
if (n < 1) {
gallery_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(
" gallery_1_active",
""
);
}
slides[gallery_1_slideIndex - 1].style.display = "block";
dots[gallery_1_slideIndex - 1].className += " gallery_1_active";
gallery_1_captionText.innerHTML =
dots[gallery_1_slideIndex - 1].alt;
}
</script>
<!-- -->
</body>
</html>
Rather than extract all the relevant parts of the css file, I have left that as a link online to the stylesheet that is used on several websites. I have also uploaded the file (global.css).
I am hoping that some additional Javascript will give me the functionality I am seeking. I know some will say "why bother - just use Bootstrap" but I really would like to do it the old-fashioned way. Speed is not a priority - I am my only client.
