Edrol97
Silver Coder
https://codepen.io/Eliot-Lord/live/jEONLYG
Hi all,
Wondering how to make a slide gallery in html on an existing page. I have multiple existing imgs in my code already and I want to assign a style to all of the slide gallery imgs without assigning it to other imgs. I also want the gallery to appear max-height and max-width as currently am displaying it in an iframe which is tricky. Full code for additional gallery below
Hi all,
Wondering how to make a slide gallery in html on an existing page. I have multiple existing imgs in my code already and I want to assign a style to all of the slide gallery imgs without assigning it to other imgs. I also want the gallery to appear max-height and max-width as currently am displaying it in an iframe which is tricky. Full code for additional gallery below
HTML:
<h2 style="text-align: center; color: #b50938">Headline News</h2>
<div class="container">
<div class="mySlides">
<div class="numbertext">Everyday Blues Calendar feature</div>
<img src="img/EverydayBlues/Everyday Blues- Eliot Lord.png" />
</div>
<div class="mySlides">
<div class="numbertext">Morning Star feature</div>
<img src="img/MorningStarFnF.png" />
</div>
<div class="mySlides">
<div class="numbertext">GreenGrads Showcase @ HEALS London</div>
<img src="img/GreenGrads Sketches/Eliot-Lord.jpg" />
</div>
<div class="mySlides">
<div class="numbertext">The Emborissment</div>
<img src="img/Art on a postcard/TheEmborisment.png" />
</div>
<div class="mySlides">
<div class="numbertext">New Contemporaries 2019</div>
<img src="img/New Contemps 2019.png" />
</div>
<div class="mySlides">
<div class="numbertext">Herne Bay Live Beach Painting</div>
<img src="img/HerneBay24/Not Far Right.jpg" />
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<div class="caption-container">
<p id="caption"></p>
</div>
<div class="row">
<div class="column">
<img
class="demo-cursor"
src="img/EverydayBlues/IMG_4770.jpeg"
style="width: 50%"
onclick="currentSlide(1)"
alt="Everyday Blues - Eliot Lord"
/>
</div>
<div class="column">
<img
class="demo-cursor"
src="img/MorningStarCover.png"
style="width: 50%"
onclick="currentSlide(2)"
alt="Morning Star Feature"
/>
</div>
<div class="column">
<img
class="demo-cursor"
src="img/background/GreenGradsSign.jpg"
style="width: 50%"
onclick="currentSlide(3)"
alt="GreenGrads Showcase @ HEALS London"
/>
</div>
<div class="column">
<img
class="demo-cursor"
src="img/Art on a postcard/Artonapostcardlogo.gif"
style="width: 50%"
onclick="currentSlide(4)"
alt="Art On A Postcard Charity Auction"
/>
</div>
<div class="column">
<img
class="demo-cursor"
src="img/New Contemporaries/forweb.jpg"
style="width: 50%"
onclick="currentSlide(5)"
alt="Boris Can't Get Clean"
/>
</div>
<div class="column">
<img
class="demo-cursor"
src="img/HerneBay24/RobMurrayRockingTheBoat.png"
style="width: 50%"
onclick="currentSlide(6)"
alt="Not Far Right, Just Plain Wrong"
/>
</div>
</div>
</div>
CSS:
@font-face {
font-family: Eliot Lord;
src: url(Fonts/Eliothand2-Regular.otf);
}
body {
font-family: Eliot Lord;
font-size: 20px;
margin: 0;
}
* {
box-sizing: border-box;
}
.demo-cursor {
vertical-align: middle;
}
/* Position the image container (needed to position the left and right arrows) */
.container {
position: relative;
}
/* Hide the images by default */
.mySlides {
display: none;
}
.mySlides img {
width: 30%;
margin: auto;
max-height: 400px;
}
/* Add a pointer when hovering over the thumbnail images */
.cursor {
cursor: pointer;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 40%;
width: auto;
padding: 16px;
margin-top: -50px;
color: #115da8;
font-weight: bold;
font-size: 20px;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: #b50938;
}
/* Number text (1/3 etc) */
.numbertext {
color: #12b6cf;
background-color: #b50938;
font-size: 14px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* Container for image text */
.caption-container {
text-align: center;
background-color: #115da8;
padding: 2px 16px;
color: white;
}
.row:after {
content: "";
display: table;
clear: both;
}
/* Six columns side by side */
.column {
float: left;
width: 16.66%;
}
/* Add a transparency effect for thumnbail images */
.demo-cursor a:hover {
opacity: 0.6;
}
.active,
.demo:hover {
opacity: 1;
}
JavaScript:
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides((slideIndex += n));
}
function currentSlide(n) {
showSlides((slideIndex = n));
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("demo");
let captionText = document.getElementById("caption");
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(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
captionText.innerHTML = dots[slideIndex - 1].alt;
}