Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a good example that I made that might help. Try it out -- <a href="http://jsfiddle.net/SuperBoi45/XMSGe/" rel="nofollow">http://jsfiddle.net/SuperBoi45/XMSGe/</a></p> <p>Here's the code for a quick look:</p> <p>HTML:</p> <pre><code>&lt;button id="before"&gt;Previous&lt;/button&gt; &lt;button id="next"&gt;Next&lt;/button&gt; &lt;div id="imageGallery"&gt;&lt;/div&gt; </code></pre> <p>JavaScript:</p> <pre><code>function $(id) { return document.getElementById(id); } var foward = null, back = null, images = [ "http://www.toxel.com/wp-content/uploads/2009/04/conceptcar04.jpg", "http://politicolnews.com/wp-content/uploads/2010/01/bill-gates-car.jpg", "http://www.youthedesigner.com/wp-content/uploads/2008/05/car-wallpapers19.jpg", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-555c9ae9cfd364db5307b2e8d717a00d", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-01589fb639efec5433a3e30a8a8dd449", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-31f8cbd6627edc1ba9ef2828f3423fdf", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-0f47a0c2db85b5d7c134d41bcdc65b2e", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-739fd589778207e542a6e31873a24433", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-6056a5df58462ea4951a2b328243b7a2", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-59028363fc0f7d0ee7aa1ebc5e72713a", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-eb09864be7a1fbe7e821bc1ee08c3a8b", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-50bd88090e05a452bba67d510ba4a0cc", "http://d2o7bfz2il9cb7.cloudfront.net/main-qimg-191b37eea296e90a242d24db90824c5c" ]; var img = new Image(); for (var i = 0; i &lt; images.length; i++) { // caching the images for performance boost img.src = images[i]; } var image = { count: -1, next: function() { if (image.count == (images.length) - 1) return false; image.count += 1; $('imageGallery').innerHTML = "&lt;img src=\"" + images[image.count] + "\"\/&gt;"; }, previous: function() { if (image.count &lt;= 0) return false; image.count -= 1; $('imageGallery').innerHTML = "&lt;img src=\"" + images[image.count] + "\"\/&gt;"; } }; foward = image.next; back = image.previous; $('next').addEventListener("click", foward); $('before').addEventListener("click", back); </code></pre> <p>The best thing about this is that all you have to do is add a new image URL to the array and it will still work. If you want to change the images but not all the content in the div, I'd recommend putting in another div outside the image gallery.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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