$(document).foundation();
var image_array = new Array();
var counter = 0;
var changeBGImageInterval;
var delay = 3000; //default
$(document).ready(function(){
console.log("Ready");
$("#hashtagSearchForm").submit(function(event){
var idelay = parseInt($("input[name=delaybox]").val());
if(isNaN(idelay) === false){
delay = idelay * 1000; // convert seconds to milliseconds (setInterval requirement)
}else{
delay = 3000; // set to default if no input
}
console.log("Fetching images with #" + $("input[name=hashtagbox]").val());
console.log("Delay: " + delay + " milliseconds");
// AJAX part
$.post(
"fetchInstagramImages.php",
{
'hashtag' : $("input[name=hashtagbox]").val()
},
function(data){
// This is triggered after the request has been completed. This is custom code.
// data = response data of request. In this case: echo json_decode($myArray);
var images = JSON.parse(data);
image_array = []; // clear array;
$(images).each(function(count){
image_array.push(images[count]);
});
// reset timed event first
clearInterval(changeBGImageInterval);
// for the timed event
changeBGImageInterval = setInterval(
function(){
$("body").css("background-image", 'url(' + image_array[counter] +')');
// console.log(image_array[counter]);
counter++;
if(counter == 20){counter = 0;}
},
delay // 3 seconds
);
}
);
event.preventDefault();
});
});
How can I preload images from my slideshow using javascript? Because doesn't load fast and it doesn't look good. Any suggestions how to? Or is there anyone who could edit this? Thanks. How can I preload images from my slideshow using javascript? Because doesn't load fast and it doesn't look good. Any suggestions how to? Or is there anyone who could edit this? Thanks