July 26, 201115 yr Hi All, I have been looking around for this answer and I'm either completely blind or just searching the wrong words. Anyhow... I have a product which I would like to have multiple image thumbnails that when clicked displayed larger in a fixed content area, but do not reload the page. How can I go out this as I am a bit lost on this one? Example (Amazon) http://www.amazon.co.uk/Kindle-Wireless-Reader-3G-Wifi-Graphite/dp/B002LVUWFE/ref=amb_link_159955307_2?pf_rd_m=A3P5ROKL5A1OLE&pf_rd_s=center-1&pf_rd_r=1698CTF1GZD462A63Y40&pf_rd_t=101&pf_rd_p=248625307&pf_rd_i=468294 Thanks in advance Idny,
July 26, 201115 yr this really isnt optimal, the reason there is 2 locations of the image url (a tag and img) is the actual page i use this on uses some jquery plugins... but ive ripped out the js code for that in this example... also not actually tested the code but should work... requires you use jQuery tho... // html <div id="thumbs"> <div class="thumb"> <a href="/images/products/tow/tow.jpg"> <img class="thumbs" src="/images/products/tow/tow.jpg" /> </a> </div> <div class="thumb"> <a href="/images/products/tjn/tjn.jpg"> <img class="thumbs" src="/images/products/tjn/tjn.jpg" /> </a> </div> </div> // jquery $('div.thumb a').each(function() { var link = $(this); link.click(function() { $('#main-img').attr('src',link.attr('href')); return false; }); }); Edited July 26, 201115 yr by SniderDK
July 26, 201115 yr Author this really isnt optimal, the reason there is 2 locations of the image url (a tag and img) is the actual page i use this on uses some jquery plugins... but ive ripped out the js code for that in this example... also not actually tested the code but should work... requires you use jQuery tho... // html <div id="thumbs"> <div class="thumb"> <a href="/images/products/tow/tow.jpg"> <img class="thumbs" src="/images/products/tow/tow.jpg" /> </a> </div> <div class="thumb"> <a href="/images/products/tjn/tjn.jpg"> <img class="thumbs" src="/images/products/tjn/tjn.jpg" /> </a> </div> </div> // jquery $('div.thumb a').each(function() { var link = $(this); link.click(function() { $('#main-img').attr('src',link.attr('href')); return false; }); }); Thanks. I will give it some testing shortly and hopefully get it working as per your advice. I also noticed you said it is not optimal. Is there a reason for this? Or a possible better method used for product images previews? Thanks
July 26, 201115 yr this could be done with pure css no need for the javascript Check out this link there is one on there. Just google css photo gallery I'm sure you'l find plenty of others.
July 26, 201115 yr be careful of the css one where it's using hover. Touch screen devices won't do anything with hover.
July 26, 201115 yr Author be careful of the css one where it's using hover. Touch screen devices won't do anything with hover. The CSS one looks nice. However, Will this work if the images are coming from a database?
July 26, 201115 yr The CSS one looks nice. However, Will this work if the images are coming from a database? doesn’t matter where the image comes from as long as there is a url for it theres a way... as Zed points out touch screens don’t do hover. I also noticed you said it is not optimal. Is there a reason for this? yes, its not optimal because in the actual usage the img tag uses a thumbnail image tow_thumb.jpg with the a tag having the url to the full size image which means if javascript is off the link takes you to the image so it degrades nicely... in the example i posted i removed the thumb and did not update the code to use the image url once and use the src value of the img to update the main image and a hash for the a tag href value... as it was for example purposes and i was mid way though some work so was being lazy... the email notification of this post just got my attention but really should of been doing my work so by not optimal i meant i should do better... but because i dint give you the full bit of html it would of forced you to play about and figure that out yourself... hopefully
Create an account or sign in to comment