adding preloading

This commit is contained in:
Josh de Leeuw 2013-11-12 12:46:21 -05:00
parent 93e2ec17bc
commit 51020fea6b

View File

@ -1,39 +1,62 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<title>jspsych-text plugin example</title> <title>jspsych-text plugin example</title>
<!-- jQuery --> <!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- jsPsych --> <!-- jsPsych -->
<script src="scripts/jspsych.js"></script> <script src="scripts/jspsych.js"></script>
<script src="scripts/plugins/jspsych-animation.js"></script> <script src="scripts/plugins/jspsych-animation.js"></script>
<!-- style --> <!-- style -->
<style> <style>
#jspsych_target { margin: 50px auto 50px auto; width: 600px; font-size:18px; text-align: center;} #jspsych_target {
#instructions { text-align: left; } margin: 50px auto 50px auto;
pre { text-align: left; } width: 600px;
font-size:18px;
text-align: center;
}
#instructions {
text-align: left;
}
pre {
text-align: left;
}
</style> </style>
</head> </head>
<body> <body>
<div id="jspsych_target"> <div id="jspsych_target"></div>
</div>
</body> </body>
<script type="text/javascript"> <script type="text/javascript">
// declare variable to hold animation sequence // declare variable to hold animation sequence
var animation_sequence = ["img/face_1.jpg","img/face_2.jpg","img/face_3.jpg","img/face_4.jpg","img/face_3.jpg","img/face_2.jpg"]; var animation_sequence = ["img/face_1.jpg", "img/face_2.jpg", "img/face_3.jpg", "img/face_4.jpg", "img/face_3.jpg", "img/face_2.jpg"];
// create animation block for jspsych // create animation block for jspsych
var animation_block = {type:'animation', stimuli: [animation_sequence], repetitions:3}; var animation_block = {
type: 'animation',
stimuli: [animation_sequence],
repetitions: 3
};
// launch jspsych experiment // preload images for animation sequence
jsPsych.init({ // call start() when loading is complete
display_element: $('#jspsych_target'), jsPsych.preloadImage(animation_sequence, start)
experiment_structure: [animation_block],
on_finish:function(data){ // function to launch jspsych experiment
$('#jspsych_target').append($("<pre>",{ // putting this in a function so that it only gets called once all the
html: JSON.stringify(data,undefined,2) // images are loaded using preloadImages
})); function start() {
} jsPsych.init({
}); display_element: $('#jspsych_target'),
experiment_structure: [animation_block],
on_finish: function(data) {
$('#jspsych_target').append($("<pre>", {
html: JSON.stringify(data, undefined, 2)
}));
}
});
}
</script> </script>
</html> </html>