3
Colleagues.
I have seen in some virtual stores that there is the feature of changing the colors of the product. How would I make sure that when I click on a certain color, the product is changed without refresh? see a model: lapupa.com.br/539sl
3
Colleagues.
I have seen in some virtual stores that there is the feature of changing the colors of the product. How would I make sure that when I click on a certain color, the product is changed without refresh? see a model: lapupa.com.br/539sl
2
You can do it this way, given that this is obviously not the same product or colors, but the logic will be this:
const prod_colors = {blue: 'https://cdn.mensagenscomamor.com/resize/400x225/content/images/int/imagens_de_deus.jpg', green: 'http://cdn.mixme.com.br/wp-content/uploads/2016/01/disney5.jpg', red: 'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTQJ8oMypN2S5RyM1S9zKxO3AOBc1UNT_EanYOIRYWK1evZVaj5'}
for(var color in prod_colors) { // adicionar dinamicamente as cores que temos à disposição ao nosso select
$('.colors').append('<div style="background-color: ' +color+ '" data-image="' +prod_colors[color]+ '"></div>');
}
$('.colors div').on('click', function() {
var img_cor = $(this).data('image');
$('.img_dinamic').prop('src', img_cor);
});
.colors div {
width: 20px;
height: 20px;
float: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img class="img_dinamic" src="https://cdn.mensagenscomamor.com/resize/400x225/content/images/int/imagens_de_deus.jpg">
<div class="colors">
</div>
<br>
Browser other questions tagged jquery
You are not signed in. Login or sign up in order to post.
Thank you for the reply Miguel, but I would actually like something similar to this model: http://www.lapupa.com.br/539sl
– user24136
@Fox.11 actually the logic is the same but it will be on the Divs click instead of a select, you could have put that specification in the question, now I don’t have much time to make that change, maybe later I can
– Miguel
Thanks Miguel. It worked.
– user24136
@Nothing Fox.11, thank God
– Miguel