javascript - How to change elements(img's) position via radio buttons? -


i got image positioned in container , 3 radio buttons. add images appear on container main image when of radio buttons chosen. each of buttons have different positions of images shown when active.

so far got that:

<div class="btn-group" data-toggle="buttons">     <label class="btn btn-default">         <input type="radio" id="q156" name="quality[25]" value="1" /> 1     </label>      <label class="btn btn-default">         <input type="radio" id="q157" name="quality[25]" value="2" /> 2     </label>      <label class="btn btn-default">         <input type="radio" id="q158" name="quality[25]" value="3" /> 3     </label>  </div> </div> </div> <div class="col-md-8 col-fl">     <div id="img_box">         <img style="width: 100%;" src="img/other/rounded_corners.png" />     </div> 

you add image sources data attr. radio button.

<div class="btn-group" data-toggle="buttons">     <label class="btn btn-default">         <input type="radio" id="q156" name="quality[25]" value="1" data-img="http://placehold.it/350x150/ff0000" /> 1     </label>      <label class="btn btn-default">         <input type="radio" id="q157" name="quality[25]" value="2" data-img="http://placehold.it/350x150/00ff00"/> 2     </label>      <label class="btn btn-default">         <input type="radio" id="q158" name="quality[25]" value="3" data-img="http://placehold.it/350x150/0000ff" /> 3     </label>  </div> <div class="col-md-8 col-fl"> <div id="img_box"></div> 

the img box empty size , image set css:

#img_box{     width: 350px;     height: 150px;     background: url('http://placehold.it/350x150/ff0000') } 

then add event append img overlay on click (using source radio buttons):

 $(function(){     $('input[type=radio]').click(function(){         $this = $(this)         $img_box = $('#img_box')         $overlay = $('<img/>').attr('src',$this.data('img'))         $img_box.html('').append($overlay)                         }); }) 

see example: https://jsfiddle.net/fmytsjv7/1/


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -