adding unique id to a stimulus in an image-button-response trial #2269
-
Hello everyone! I am trying to adjust the size of an image depending on the size of the screen each participant is using (or more specifically the window they are viewing). For example, if the window width is beyond 1366 px and if the window height is beyond 768 px, I want the image to be 350x350 px, if the width and height are below these values, I want the image to be 200x200 px). I have tried to achieve this in the following way:
However, I'd like to move this responsive design attempt to the custom CSS file and access this particular image through a unique id. The standard img tag in HTML is not working (see one attempt below). Does anyone have any ideas on how to do this? Also, any advice on how to optimize this responsive design attempt would be very helpful!
Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @jelkastojanov, One simple solution would be to use the |
Beta Was this translation helpful? Give feedback.
-
Hi @jelkastojanov, just to expand a bit on Josh's answer: you could use the var squareTrial = {
type: 'html-button-response',
prompt:'<div class="text-above-image"> In the first part of the study, you were assigned to the SQUARE group.<br> Please acknowledge your group membership before proceeding.</div>',
stimulus: '<img src = "assets/images/Square_group.png" id = "squareImage" />',
choices: ['I acknowledge that I am a member of the SQUARE group.']
}; And then you should be able to use that image ID in your CSS selector. #squareImage {
height: 45vh;
width: 25vw;
} Another option is to use CSS media queries, which might be more useful if you want to create separate dimension/device categories, rather than always using the same percentage of the viewport height/width. More info here: https://www.learnhowtoprogram.com/lessons/viewports-and-media-queries Finally, you could look at CSS custom properties (variables), which allow you to use variables inside your CSS. The values of these variables can be set in the CSS and in JavaScript. This is probably overkill for what you need, but it can be useful if you want to re-use the same variable value in multiple places in your CSS rules, and/or if you want to calculate a CSS value based on one or more variables using the CSS I hope this helps. Please let us know if you need further guidance, and if you come up with a good solution to share! |
Beta Was this translation helpful? Give feedback.
Hi @jelkastojanov, just to expand a bit on Josh's answer: you could use the
html-button-response
plugin to give your image a unique ID:And then you should be able to use that image ID in your CSS selector.
As far as getting a responsive CSS solution to the image size, one option might be to use a …