PricingBlog

Can we change the background IMG based on the status of a variable?

  • uunicode-1271126320847257651

    unicodes

    1 year ago

    I have a variable (T/F) and based on that I want to change the background of a div. It is possible?
  • uunicode-1271126729171406848

    unicodes

    1 year ago

    Can we change the background IMG based on the status of a variable?
  • tomthebigtree-1271130206312071249

    Tom Ireland

    1 year ago

    Should be possible. Are you using an uploaded image, URL or colour?

    Depends on how you're handling it but you could store values in an object and then make changes based on the status of the variable e.g. true or false, etc., then depending on the condition, get the specific path (key/value) from your object.
    🙏1
  • tomthebigtree-1271132526567755879

    Tom Ireland

    1 year ago

    If you're not using an image in a div and using the background CSS style, you could set up a style variable to handle the logic and apply it. For example, if var is equal to x then style-variable = y-colour else style-variable = z-colour
    🙏1
  • tomthebigtree-1271135100108673076

    Tom Ireland

    1 year ago

    If you're looking for a quick and dirty example, check out https://flocus_clone.toddle.site/. After you enter your name, you can pick a theme, which updates the background image. In this case, I'm using an image in a div, which is more semantic and adds a bit more scope to what's possible. I'm using image URLs, so I just have a trigger to set the src for the image depending on what option I'm selecting, which is what is stored in a variable. Many ways to skin a cat.
    🙏2
  • uunicode-1271153536834601054

    unicodes

    1 year ago

    Thank you Tom, great solution of using an image in a div. It is easy to implement. Thank you very much for your help 🙏
    🙌1