Attempting to create functionality for an image selector carousel
functionality of image selector:
- click an img in container below main image
- clicked img displays in main image container
- previous displayed main img populates into container below main image in place of selected img
html
<div class="single-pro-images">
<div class="main-image" onclick="clicked();">
<img src="https://cdn.marvel.com/u/prod/marvel/i/mg/b/e0/56a7c0725bcbb/clean.jpg" width="100%" alt=""></div>
<div class="small-img-group">
<div class="small-img-col">
<img src="https://ids.si.edu/ids/deliveryService?max=800&id=https%3A%2F%2Famericanhistory.si.edu%2Fsites%2Fdefault%2Ffiles%2FAHB2008q04107.jpg" width="100%" class="small-img" alt="">
</div>
<div class="small-img-col">
<img src="https://i0.wp.com/blog.gocollect.com/wp-content/uploads/2022/02/75960620003000431.jpg?ssl=1" width="100%" class="small-img" alt="">
</div>
<div class="small-img-col">
<img src="https://cdn.marvel.com/content/1x/fcbdasmven2023_cover-resized.jpg" width="100%" class="small-img" alt="">
</div>
</div>
</div>
css
.single-pro-images {
width: 25%;
margin: 0px 15px 0px 0px;
}
.small-img-group {
display: flex;
justify-content: space-between;
margin-top: 15px;
}
.small-img-col {
flex-basis: 24%;
cursor: pointer;
}
Started the code by attempting to grab the main image src and have the console log display true or false if the image src were not equal, and when the srcs are not equal the main image will change. Stuck on writing the if-statement because I'm sure if images can be stored as values.
JS
let mainImg = document.getElementsByClassName("main-image");
function clicked() {
if (mainImg !== "https://cdn.marvel.com/u/prod/marvel/i/mg/b/e0/56a7c0725bcbb/clean.jpg"); {
console.log(true);
}
Learned booleans/if-statements and functions yesterday, attempting to apply the lessons today but feels like I'm putting the cart before the horse.
So here is my new clicked function with arg = newSrc givin as parameter
also you need to change the HTML CODE like this
you just need to change the 1.jpg etc to your images src