Pixel count on canvas not correct #1764
-
Hello all, In my experiment i display canvases that need to be as big as my screen, 1080x1920 pixels. However, when i use Can anyone explain/suggest how to fix this? For my experiment, the size of objects is rather important, so i need to know for sure that 66 pixels equal 1 cm, for instance. Is there maybe a way to do this?: I'm open to any suggestion, thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hi @DanielBruijn, if you open the browser's developer tools and find the Elements tab, you'll see that the canvas element is actually nested under a few different things: body -> jspsych-content-wrapper-div -> jspsych-content div -> jspsych-canvas-keyboard-response-stimulus div -> canvas element. Most of these things have a height and width of 100%, except for the jspsych-content div, which has a max-width of 95%. This means that, by default, all of the jsPsych content will be slightly more narrow than the page width. You can change that like this: <style>#jspsych-content {max-width:100%;}</style> Then, to get the size of the browser page to use for the canvas height and width, you can use the var canvas_h = document.getElementsByTagName('body')[0].clientHeight;
var canvas_w = document.getElementsByTagName('body')[0].clientWidth; I hope this helps. Let us know if it works, and if you have any other questions. |
Beta Was this translation helpful? Give feedback.
Hi @DanielBruijn, if you open the browser's developer tools and find the Elements tab, you'll see that the canvas element is actually nested under a few different things: body -> jspsych-content-wrapper-div -> jspsych-content div -> jspsych-canvas-keyboard-response-stimulus div -> canvas element. Most of these things have a height and width of 100%, except for the jspsych-content div, which has a max-width of 95%. This means that, by default, all of the jsPsych content will be slightly more narrow than the page width. You can change that like this:
Then, to get the size of the browser page to use for the canvas height and width, you can us…