Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>See this example:</p> <p><strong>No preloading</strong></p> <p>HTML:</p> <pre><code>&lt;div id="big-image"&gt; &lt;img src="http://lorempixel.com/400/200/sports/1/"&gt; &lt;/div&gt; &lt;div class="small-images"&gt; &lt;a href="http://lorempixel.com/400/200/sports/1/"&gt;&lt;img src="http://lorempixel.com/100/50/sports/1/"&gt;&lt;/a&gt; &lt;a href="http://lorempixel.com/400/200/fashion/1/" class=""&gt;&lt;img src="http://lorempixel.com/100/50/fashion/1/"&gt;&lt;/a&gt; &lt;a href="http://lorempixel.com/400/200/city/1/"&gt;&lt;img src="http://lorempixel.com/100/50/city/1/"&gt;&lt;/a&gt; &lt;/div&gt; </code></pre> <p>Javascript (jQuery)</p> <pre><code>$(function(){ $(".small-images a").click(function(e){ var href = $(this).attr("href"); $("#big-image img").attr("src", href); e.preventDefault(); return false; }); }); </code></pre> <p>Currently only 1 big image, when clicking on an A, the href of the A is copied as SRC of the big image.</p> <p>Live example: <a href="http://jsfiddle.net/Qhdaz/1/" rel="noreferrer">http://jsfiddle.net/Qhdaz/1/</a></p> <p>If you wan't to do it without the extra DOM progressing, you can add 3 big images, and load them directly. The above solution does not preload the images, the below function will.</p> <p><strong>With preloading</strong></p> <p>HTML:</p> <pre><code>&lt;div id="big-image"&gt; &lt;img src="http://lorempixel.com/400/200/sports/1/"&gt; &lt;img src="http://lorempixel.com/400/200/fashion/1/"&gt; &lt;img src="http://lorempixel.com/400/200/city/1/"&gt; &lt;/div&gt; &lt;div class="small-images"&gt; &lt;img src="http://lorempixel.com/100/50/sports/1/"&gt; &lt;img src="http://lorempixel.com/100/50/fashion/1/"&gt; &lt;img src="http://lorempixel.com/100/50/city/1/"&gt; &lt;/div&gt; </code></pre> <p>Javascript:</p> <pre><code>$(function(){ $("#big-image img:eq(0)").nextAll().hide(); $(".small-images img").click(function(e){ var index = $(this).index(); $("#big-image img").eq(index).show().siblings().hide(); }); }); </code></pre> <p><a href="http://jsfiddle.net/Qhdaz/2/" rel="noreferrer">http://jsfiddle.net/Qhdaz/2/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload