You can do this with this simple javascript function, with JQuery:
If you had the same image for all labels and only rotated the images, you would have to do this only once. As follows
$('input[type="checkbox"]').click(function() {
if ($(this).is(":checked")) {
$(this).closest('div').children('label').children('img').attr("src", "imagem-vermelha");
}else{
$(this).closest('div').children('label').children('img').attr("src", "imagem-verde");
}
})
Unfortunately, in your current case, you should repeat this for all checkboxes, since every label
has different images.
I used the method .closest()
which basically looks for the attencessor element, and the .children()
", which looks for the child elements using the argument, which in this case was a img
.
It would look like this:
$('#i1').click(function() {
if ($(this).is(":checked")) {
$(this).closest('div').children('label').children('img').attr("src", "http://franceimagecoaching.com.br/wp-content/themes/biznex/img/blog-type-article.png");
}else{
$(this).closest('div').children('label').children('img').attr("src", "http://i.imgur.com/OpIgi4H.png");
}
})
$('#i2').click(function() {
if ($(this).is(":checked")) {
$(this).closest('div').children('label').children('img').attr("src", "http://franceimagecoaching.com.br/wp-content/themes/biznex/img/blog-type-article.png");
}else{
$(this).closest('div').children('label').children('img').attr("src", "http://i.imgur.com/8Iyy2C4.png");
}
})
$('#i3').click(function() {
if ($(this).is(":checked")) {
$(this).closest('div').children('label').children('img').attr("src", "http://franceimagecoaching.com.br/wp-content/themes/biznex/img/blog-type-article.png");
}else{
$(this).closest('div').children('label').children('img').attr("src", "http://i.imgur.com/M6hK389.png");
}
})
$('#i4').click(function() {
if ($(this).is(":checked")) {
$(this).closest('div').children('label').children('img').attr("src", "http://franceimagecoaching.com.br/wp-content/themes/biznex/img/blog-type-article.png");
}else{
$(this).closest('div').children('label').children('img').attr("src", "http://i.imgur.com/M5UHtdt.png");
}
})
$('#i5').click(function() {
if ($(this).is(":checked")) {
$(this).closest('div').children('label').children('img').attr("src", "http://franceimagecoaching.com.br/wp-content/themes/biznex/img/blog-type-article.png");
}else{
$(this).closest('div').children('label').children('img').attr("src", "http://i.imgur.com/XWX98Fc.png");
}
})
$('#i6').click(function() {
if ($(this).is(":checked")) {
$(this).closest('div').children('label').children('img').attr("src", "http://franceimagecoaching.com.br/wp-content/themes/biznex/img/blog-type-article.png");
}else{
$(this).closest('div').children('label').children('img').attr("src", "http://i.imgur.com/cdasBJA.png");
}
})
.imagens input[type="checkbox"] {
visibility: hidden;
}
.imagens label {
display: block;
border: 1px solid #666;
width: 50px;
}
.imagens input[type="checkbox"]:checked+label {
border-color: #ccf;
}
.imagens img {}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divstyle="width: 700px; height: 850px; position: absolute; left: -20px;">
<div class="imagens" style="position: static; left: 90px; width: 130px; height: 129px; ">
<div style="position: absolute; left: 55px; ">
<div style="position: absolute; left: 29px; top: 38px;"><img src="http://i.imgur.com/Ww2xT7t.png"/></div><divstyle="position: absolute; left: 7px; top: 2px">
<input type="checkbox" name="imagem" id="i1" />
<label for="i1"><img src="http://i.imgur.com/OpIgi4H.png"/></label></div><divstyle="position: absolute; left: 50px; top: -15px;">
<input type="checkbox" name="imagem" id="i2" />
<label for="i2"><img src="http://i.imgur.com/8Iyy2C4.png"/></label></div><divstyle="position: absolute; left: 94px; top: 5px">
<input type="checkbox" name="imagem" id="i3" />
<label for="i3"><img src="http://i.imgur.com/M6hK389.png"/></label></div><divstyle="position: absolute; left: 97px; top: 55px">
<input type="checkbox" name="imagem" id="i4" />
<label for="i4"><img src="http://i.imgur.com/M5UHtdt.png"/></label></div><divstyle="position: absolute; left: 49px; top: 90px;">
<input type="checkbox" name="imagem" id="i5" />
<label for="i5"><img src="http://i.imgur.com/XWX98Fc.png"/></label></div><divstyle="position: absolute; left: 3px; top: 55px">
<input type="checkbox" name="imagem" id="i6" />
<label for="i6"><img src="http://i.imgur.com/cdasBJA.png"/></label></div></div></div></div>
Injavascript,ineachcheckbox,youwouldhavetoputeachimageforwhenitwascheckedandwhenitwasunchecked.
InyourHTML,I'vemadesomechanges,fixingtheclosingofsometagsandorganizingthecedeiras,givingthemaposition:absolute
andpositioningthemmanually.
UPDATE
Forthechairtoturnredwithouttheneedofclick
,Icreatedafunctionforeverycheckbox
.Forexample,thatof#i1
.
$('#i1').click(i1);functioni1(){if($('#i1').is(":checked")) {
$('#i1').closest('div').children('label').children('img').attr("src", "http://franceimagecoaching.com.br/wp-content/themes/biznex/img/blog-type-article.png");
} else {
$('#i1').closest('div').children('label').children('img').attr("src", "http://i.imgur.com/OpIgi4H.png");
}
}
And at the end of the code, call all functions:
i1();
i2();
...
i6();
Example - JsFiddle
I used an example image as it did not have every red chair.