Simple JavaScript Photo Gallery

The Fiddle is a starting point for the Module 12 lab assignment at Saint Paul College.

by Susan Metoxen

HTML

<div class="gallery">

    <div class="preview">
        <img id="preview" src="http://whitebuffalosolutions.com/WB-Template/images/photo6.jpg" style="display:block;margin:0 auto;" alt=""  height="600" width="800"/>
    </div>

    <div class="gallery-thumbnails" style="margin:0 auto;text-align:center">
        <img onclick="document.getElementById('preview').src=document.getElementById('img1').src" id="img1" src="http://whitebuffalosolutions.com/WB-Template/images/photo1.jpg" alt="" />
        <img onclick="document.getElementById('preview').src= document.getElementById('img2').src;" id="img2" src="http://whitebuffalosolutions.com/WB-Template/images/photo2.jpg" alt=""  />
        <img onclick="document.getElementById('preview').src = document.getElementById('img3').src;" id="img3" src="http://whitebuffalosolutions.com/WB-Template/images/photo3.jpg" alt="" />
        <img onclick="document.getElementById('preview').src = document.getElementById('img4').src;" id="img4" src="http://whitebuffalosolutions.com/WB-Template/images/photo4.jpg" alt="" />
        <img onclick="document.getElementById('preview').src = document.getElementById('img5').src;" id="img5" src="http://whitebuffalosolutions.com/WB-Template/images/photo5.jpg" alt=""  />
        <img onclick="document.getElementById('preview').src = document.getElementById('img6').src;" id="img6" src="http://whitebuffalosolutions.com/WB-Template/images/photo7.jpg" alt="" />
        <img onclick="document.getElementById('preview').src = document.getElementById('img7').src;" id="img7" src="http://whitebuffalosolutions.com/WB-Template/images/photo9.jpg" alt="" />
        <img onclick="document.getElementById('preview').src = document.getElementById('img8').src;" id="img8" src="http://whitebuffalosolutions.com/WB-Template/images/photo10.jpg" alt="" />
    </div>
    
</div>

CSS

.gallery .preview{
    width: 100%;
    height: auto;
}

.gallery .gallery-thumbnails img {
    width: 100px;
    height: 75px;
    margin: 3px 10px 10px 0;
}

.gallery .gallery-thumbnails img:hover {
    opacity: 0.8;
    cursor: pointer;
}

.gallery .preview img#preview {
    padding: 1px;
    max-width: 100%;
    height: auto;
    margin: 0 auto !important;
    display: block !important;
}