2016-12-31 129 views
0

如何讓每幅圖像可調整大小和拖動?div中可調整大小和可拖動的圖像

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(); 
 

 
    }); 
 

 
});
.imgcontainerss { 
 
    float: left; 
 
}
<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>

回答

1

更新小提琴代碼,增加了可拖動和resizable圖像

需要點擊圖片放大並調整其大小。

$(document).ready(function() { 
 
    $('#imajes').change(function() { 
 
    $('.subselector').hide(); 
 
    $('.smallimages').hide(); 
 
    $('#' + $(this).val()).show(); 
 
\t 
 
    }); 
 
    
 
    $('.smallimages').hide(); 
 
    var id = $(this).attr('id'); 
 
    var val = $(this).val(); 
 
\t 
 
\t 
 
$('#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(); 
 
\t   $('.modal-content').resizable(); 
 

 

 
}); 
 

 
    
 
    
 
});
.imgcontainerss{ 
 
    float:left; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
 
<script type="text/javascript" 
 
\t src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script> 
 
<link rel="stylesheet" type="text/css" 
 
\t 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>

+0

可能是錯誤的代碼?其不可調整大小 – xcalliber

+0

除了任何代碼示例外,答案還應包括一些解釋。只有代碼答案沒有太大的幫助。 –

+0

我遇到了另一個問題,當我點擊第二張圖片來同時顯示兩張圖片同時代替一張圖片時 – xcalliber

相關問題