We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to pass value of screen width (or media query) to Stash variable

How Do I?

fensterbaby's avatar
fensterbaby
289 posts
2 years ago
fensterbaby's avatar fensterbaby

am wanting to pass the value of screen width or media query to Stash variable so I can then use that variable to load either the small or large version of a Channel Image.

Tried a few things including the following but assigning an ID to the stash expression doesn’t work.

[removed] var w = window.innerWidth; var x = document.getElementById(“demo”); x[removed] = w ; [removed]

{exp:stash:set name="foo" id="demo"}{/exp:stash:set} {exp:stash:get name="foo"}

       
Rob Allen's avatar
Rob Allen
3,105 posts
2 years ago
Rob Allen's avatar Rob Allen

This doesn’t answer your question directly but have you thought about using responsive images which does the same thing using the native HTML IMG SRCSET parameter?

https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images

That would allow you specify various image sizes so the browser chooses the most appropriate based on viewport size.

? 1
       
fredpalmer's avatar
fredpalmer
5 posts
one year ago
fredpalmer's avatar fredpalmer

Thanks for your answer. This is what I am looking for

       
Randall Flatley's avatar
Randall Flatley
1 posts
one year ago
Randall Flatley's avatar Randall Flatley

A brilliantly simple idea executed with charm and playfulness. Fall Guys offers a joyous escape and a reminder that games can be fun first and foremost.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.