I am new to the world of HTML/CSS and have been struggling with a jQuery challenge while building my first website. My goal is to create a jQuery-powered image gallery using thumbnails. I found a tutorial by Ivan Lazarevic () and also sought help from Stackoverflow's forum via this thread: .
The code provided replaces the displayed large image with a larger version of the thumbnail when clicked. However, this works smoothly only for pictures with the same orientation. To address this, I have separate code snippets in two different files for horizontal and vertical images:
<div id="mainImage">
<img id="largeImage" src="Images/Projects/UOW/UOWII_large.jpg"/>
</div>
AND:
<div id="mainImageVERTICAL">
<img id="largeImageVERTICAL" src="Images/Projects/UOW/UOWI_large.jpg" />
</div>
I have created different CSS rules for largeImage and largeImageVERTICAL based on portrait or landscape orientation of the images.
#largeImage {
position: fixed;
height: 83%;
width:auto;
top: 15%;
left: 5%;
}
AND:
#largeImageVERTICAL {
position: fixed;
height: 83%;
width:auto;
top: 15%;
left: 36.36%;
}
These rules position the images differently on the screen. However, I am seeking guidance on how to modify my code so that I can handle both portrait and landscape-oriented images by applying the correct CSS rule to each. Currently, I am following Lazarevic's approach which includes:
$('#thumbs img').click(function(){
$('#largeImage').attr('src',$(this).attr('src').replace('thumb','large'));
});
This code simply swaps the thumbnails with larger images. I want to dynamically apply the appropriate CSS rule based on the orientation of the image clicked. I believe this requires some JavaScript coding, which I am not familiar with.
I would greatly appreciate any assistance to move forward with this project. Any suggestions on how to achieve this? Perhaps a JS function that determines which CSS rule to use based on the clicked image? I am currently stuck and in need of guidance...
Thank you in advance!