I am trying to create a product configurator for the company I work for, and so far I have Google's Model Viewer doing just what I want! I am able to change the size and color of the product, however, I am wanting to change the "dropdown" of the variant selector to a "grid" to act more like buttons rather than a dropdown list. As I now only have about a months worth of history working in HTML, CSS, and JS I am not sure how to go about this. I have images for each swatch of color that I am wanting to populate the options with.
I've also tried using DDSlick Jquery to act more as a dropdown list that has images (for the swatch colors) but I couldn't figure out how to get that to work either.
Any help with this would be greatly appreciated!
<div>
Choose a Color:
<select id="variant"></select>
</div>
<script>
const modelViewerVariants = document.querySelector("model-viewer#MalloryChest36");
const select = document.querySelector('#variant');
modelViewerVariants.addEventListener('load', () => {
const names = modelViewerVariants.availableVariants;
for (const name of names) {
const option = document.createElement('option');
option.value = name;
option.textContent = name;
select.appendChild(option);
}
});
select.addEventListener('input', (event) => {
modelViewerVariants.variantName = event.target.value;
});
</script>