I am pretty new to HTML / CSS and have had a jquery problem since I started building my first website. I want to create a jQuery-enabled image gallery using thumbnails. The textbook I followed was Ivan Lazarevich in this regard ( http://workshop.rs/2010/07/create-image-gallery-in-4-lines-of-jquery/ ). I also used the Stackoverflow forum through this thread: http://goo.gl/ILzsx .
The code that he provides replaces the large image on the display with the larger version of the thumbnail that was clicked. This seems to work quite smoothly, but only for images that have the same orientation. The following code appears in two different files, thereby setting the difference between 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 created different CSS rules for the largeImage and largeImageVERTICAL parameters, depending on whether the image has portrait or landscape orientation.
#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 two rules simply place images at different points on the screen. However, I would like to know how to change my code so that I can create a page with images with a portrait and a landscape using a CSS rule that belongs to everyone. So far, I have what I got from Lazarevichβs approach, namely:
$('#thumbs img').click(function(){ $('#largeImage').attr('src',$(this).attr('src').replace('thumb','large')); });
This code simply replaces thumbnails with large images. As said, I want to have the right to apply the correct rule to the correct image, and I suggest that this should be done using some JS coding, which I know almost nothing about.
I would appreciate some help so that I can continue this project. Any ideas how to make this work? Maybe a JS function that tells the machine to use one or the other CSS rule, depending on which image is clicked? I'm really stuck here ...
Thanks in advance!