Centre stimulus vertically + inter-trial stimulus

583 views
Skip to first unread message

david....@gmail.com

unread,
Jul 2, 2015, 5:26:17 PM7/2/15
to jsp...@googlegroups.com
Hi there,

I am programming an experiment based on the single-stim plugin. I haven’t yet managed to find a way to adapt the plugin to perform the two following things:

1) I want the stimulus (a simple image of known dimensions) to be displayed at the centre of the browser. Centering it horizontally is straight-forward, but I haven’t managed to centre it vertically. I tried using a table, with window.innerHeight as its height attribute, and then vertically aligning the image inside the only cell, but the table starts too low, so the stimulus appears too low as well… Any idea?

2) I also need to add a fixation point between trials. What would be the easiest way to do this?

Many thanks for your ideas,

David

Josh de Leeuw

unread,
Jul 2, 2015, 10:05:41 PM7/2/15
to david....@gmail.com, jsp...@googlegroups.com
Hi, David.

You could try using this technique to vertically center stimuli: http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/

If you are using the jspsych CSS file, then you may need to override some of the default values for the .jspsych-display-element class: https://github.com/jodeleeuw/jsPsych/blob/master/css/jspsych.css#L99. You could either edit the jspsych stylesheet directly or add in overriding styles in a <style> tag in the head section of the document.

The way that I typically add a fixation point is by using a single-stim trial with a + sign as the stimulus. You can interleave fixation trials with the image trials:

var image_stimuli = ['imgA.jpg', 'imgB.jpg', 'imgC.jpg'];

var timeline = [];

var fixation_trial = {
  type: 'single-stim',
  stimuli: ['<p style="font-size:32px; text-align:center">+</p>'],
  timing_response: 500, // how long to show the fixation for in ms
  response_ends_trial: false,
  choices: 'none', // no valid keys
  timing_post_trial: 0, // no gap between fixation and image
  is_html: true
}

for(var i=0; i<image_stimuli.length; i++){
 
  timeline.push(fixation_trial);

  timeline.push({
    type: 'single-stim',
    stimuli: [image_stimuli[i]],
    // other parameters for your image trial
  });
}

jsPsych.init({
  experiment_structure: timeline
});

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/c7ea33b6-9b90-4330-a89f-49cfee0c4379%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Acunzo

unread,
Jul 3, 2015, 1:52:39 PM7/3/15
to Josh de Leeuw, jsp...@googlegroups.com
Hi Josh,

Many thanks for your quick reply.

As you suggested, I modified the CSS. I used the technique proposed here, which suits my purposes for now: http://stackoverflow.com/questions/16688484/vertically-align-a-div-in-the-browser-window-not-within-another-element

Your method for the inter-trial stimulus works nicely.

Best,

David

Philip Quinlan

unread,
Nov 11, 2016, 10:17:51 AM11/11/16
to jsPsych, josh.d...@gmail.com, david....@gmail.com
Hi
I am really struggling with this and wondered if you might provide a code snippet that provides an example of how to vertically center a text string for example.

With thanks in anticipation,

Philip.

Josh de Leeuw

unread,
Nov 11, 2016, 10:22:18 AM11/11/16
to Philip Quinlan, jsPsych, david....@gmail.com
The latest (not yet released) version of jsPsych centers all content vertically by default. You could download the library from the master branch of GitHub and have vertical centering that way.

There's a nice code snippet on this page that walks through the explanation if you want to write the HTML for version 5.x

taylor...@gmail.com

unread,
Apr 30, 2017, 5:12:15 PM4/30/17
to jsPsych, philip....@york.ac.uk, david....@gmail.com
Hi Josh,

I took the approach of downloading the unreleased version. This worked very well for vertically centering the stimuli, but now a bit of my code that calculates subject accuracy no longer works. I'm getting the error that 'jsPsych.data.getTrialsOfType is not a function'. Does interacting with the data work differently in the unreleased version?

Thanks!
Taylor

Josh de Leeuw

unread,
Apr 30, 2017, 5:24:33 PM4/30/17
to taylor...@gmail.com, jsPsych, philip....@york.ac.uk, david....@gmail.com
Yes, the data module has been overhauled. This is the equivalent to the old getTrialsOfType() command:

//OLD (version 5)
jsPsych.data.getTrialsOfType('single-stim');

// NEW (version 6)
jsPsych.data.get().filter({trial_type: 'single-stim'}).values()

taylor...@gmail.com

unread,
Apr 30, 2017, 5:29:30 PM4/30/17
to jsPsych, taylor...@gmail.com, philip....@york.ac.uk, david....@gmail.com
That worked, thank you!!
Reply all
Reply to author
Forward
0 new messages