jsPsych/examples/jspsych-xab.html
2013-11-12 12:41:55 -05:00

75 lines
2.2 KiB
HTML

<!doctype html>
<html>
<head>
<title>jspsych-xab plugin example</title>
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- jsPsych -->
<script src="scripts/jspsych.js"></script>
<script src="scripts/plugins/jspsych-xab.js"></script>
<!-- style -->
<style>
#jspsych_target {
margin: 50px auto 50px auto;
width: 600px;
font-size:18px;
text-align: center;
}
#instructions {
text-align: left;
}
pre {
text-align: left;
}
img {
width: 150px;
margin: 30px;
}
</style>
</head>
<body>
<div id="jspsych_target"></div>
</body>
<script type="text/javascript">
// how many trials?
var n_trials = 6;
// declare an array to hold the stimuli
var stimuli = [];
for (var i = 1; i <= 12; i++) {
stimuli.push("img/cell_img_" + i + ".jpg");
}
var pairs = [];
for(var i = 0; i < n_trials; i++){
// randomly choose the two stimuli we will show to subject
var first_stim = stimuli[Math.floor(Math.random()*stimuli.length)];
var second_stim = stimuli[Math.floor(Math.random()*stimuli.length)];
// add the pair
pairs.push([first_stim, second_stim]);
}
// create free-sort block for jspsych
var xab_block = {
type: 'xab',
stimuli: pairs,
prompt: "<p>Identify the image that is identical to the one you just saw. Press Q for the left image, Press P for the right image.</p>"
};
// launch jspsych experiment
jsPsych.init({
display_element: $('#jspsych_target'),
experiment_structure: [xab_block],
on_finish: function(data) {
$('#jspsych_target').append($("<pre>", {
html: JSON.stringify(data, undefined, 2)
}));
}
});
</script>
</html>