I am working on a slideshow that contains hundreds of images that the user can navigate by clicking 'next' or 'previous' buttons. The way my code is currently set up, every time a user makes a navigational decision to click next or prev, a new image is loaded at that time (image paths are stored in the array). To improve load time for every image navigated, I am trying to come up with a way to load the previous 5 images and next 5 images at any given time.
So if a user is currently on imageAry[i]
, I would like to load imageAry[i-5]
up until imageAry[i+5]
. Doing so will significantly increase the feel of the how the slideshow works.
Thank you in advance.
My JavaScript
var index=0;
$('.catalog-img-container').attr("src", img_array[index]);
$('#dialog').jqm();
$(".next").click(function(){
$('.catalog-img-container').attr("src", img_array[++index%arrayLength]);
});
$(".previous").click(function(){
if (--index < 0) index = arrayLength - 1;
$('.catalog-img-container').attr("src", img_array[index%arrayLength]);
});
My Markup
<div class="catalogFrame">
<img class="catalog-img-container" src="">
</div>