diff --git a/jspsych.js b/jspsych.js index 8e702a4f..89184ec2 100755 --- a/jspsych.js +++ b/jspsych.js @@ -144,6 +144,33 @@ return exp_start_time; }; + // core.preloadImage will load images into the browser cache so that they appear quickly when + // used during a trial. + // images: array of paths to images + // callback_complete: a function with no arguments that calls when loading is complete + // callback_load: a function with a single argument that calls whenever an image is loaded + // argument is the number of images currently loaded. + + core.preloadImages = function(images, callback_complete, callback_load){ + var n_loaded = 0; + var loadfn = (typeof callback_load === 'undefined') ? function(){} : callback_load; + var finishfn = (typeof callback_complete === 'undefined') ? function(){} : callback_complete; + + for(var i=0;i