I'm currently working on my product page, where all variation options are displayed on a single page. I would like to change the background color of the page based on the selected Flavor.
For example, when one flavor is selected, the bg color changes smoothly to the flavor's picture bg color. Here's the link: https://www.yak9chews.com/collections/yak9-chews/products/test-all-chews-and-flavors?variant=4202493
I'm thinking the basic idea is to use a conditional structure like this:
if (variation == variationNumber) {
bgColor = "someColorHex";
} else if (variation == variationNumber1) {
bgColor = "someColorHex2";
} else { // rest of conditions cases
bgColor = default;
}
However, I'm not certain about this approach. I've been struggling with this issue for a month now and would appreciate any assistance. Thank you.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/a1MZYkI
Comments
Post a Comment