div中可调整大小和可拖动的图像

时间:2016-12-31 02:39:47

标签: javascript jquery html css jquery-ui

如何使每张图像可调整大小和可拖动?

Bellow是一小段代码,允许用户选择他或她想要显示的图像。他们可以随心所欲地选择两者。

我想要做的是让用户调整div中的图像并将其拖动。



$(document).ready(function() {
  $('#imajes').change(function() {
    $('.subselector').hide();
    $('.smallimages').hide();
    $('#' + $(this).val()).show();

  });

  $('.smallimages').hide();
  var id = $(this).attr('id');
  var val = $(this).val();


  $('#dog').on('change', function() {

    $("#bulldogimges").css('display', (this.value == 'bulldog') ? 'block' : 'none');

  });

  $('img').on('click', function() {
    $('#fotos').append('<img class="modal-content" src="' + $(this).attr('src') + '">');
    $('#fotos').draggable();
    $('#imgdisplay').resizable();

  });

});
&#13;
.imgcontainerss {
  float: left;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>


<div id="fotos">
  <img class="modal-content" id="imgdisplay" />
</div>

<select id="imajes">
  <option value="">Choose Image</option>
  <option value="dog">Dog</option>

</select>
<select id="dog" name="subselector" class="subselector" style="display:none">
  <option value="">Choose an item</option>
  <option value="bulldog">Bulldog</option>

</select>


<div style='display:none;' id="bulldogimges" class="smallimages">
  <div class="imgcontainerss" data-image="https://torcdesign.com/clipart/pT78gE6pc.gif">
    <img src="https://torcdesign.com/clipart/pT78gE6pc.gif" alt="Smiley face" width="55" height="55">
  </div>
  <div class="imgcontainerss" data-image="https://torcdesign.com/clipart/LiKkRqkeT.gif">
    <img src="https://torcdesign.com/clipart/LiKkRqkeT.gif" alt="Smiley face" width="55" height="55">
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

更新小提琴代码并添加可拖动和可调整大小的图像

需要点击图片放大并调整大小。

&#13;
&#13;
$(document).ready(function() {
  $('#imajes').change(function() {
    $('.subselector').hide();
    $('.smallimages').hide();
    $('#' + $(this).val()).show();
	
  });
  
    $('.smallimages').hide();
    var id = $(this).attr('id');
    var val = $(this).val();
	
	
$('#dog').on('change', function() {
  
  $("#bulldogimges").css('display', (this.value == 'bulldog') ? 'block' : 'none');

});

$('img').on('click', function() {
    $('#fotos').append('<div class="imgdrag"><img class="modal-content" src="' + $(this).attr('src')+ '"/></div>'); $('.imgdrag').draggable();
$('#fotos').droppable();
	           $('.modal-content').resizable();


});

  
  
});
&#13;
.imgcontainerss{
    float:left;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" 
	src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" 
	href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/>

<div id="fotos" ><img class="modal-content" id="imgdisplay" /></div>

<select id="imajes">
        <option value="">Choose Image</option>
        <option value="dog">Dog</option>
       
    </select> <select id="dog" name="subselector" class="subselector" style="display:none">
  <option value="">Choose an item</option>
  <option value="bulldog">Bulldog</option>
 
</select>


<div style='display:none;' id="bulldogimges" class="smallimages">
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/pT78gE6pc.gif">
    <img src="https://torcdesign.com/clipart/pT78gE6pc.gif" alt="Smiley face" width="55" height="55">
  </div>
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/LiKkRqkeT.gif">
    <img src="https://torcdesign.com/clipart/LiKkRqkeT.gif" alt="Smiley face" width="55" height="55">
  </div></div>
&#13;
&#13;
&#13;