Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Change Image without Reloading Page

Featured Replies

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,

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 by SniderDK

  • 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

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.

be careful of the css one where it's using hover. Touch screen devices won't do anything with hover.

  • 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?

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.