0
當前我正試圖使用jQuery拖放功能在畫布上繪製圖像。我試過這個。在畫布上應用可調整大小的圖像
<canvas id="c" width="200" height="200"></canvas>
<br>
<div style="display:inline-block;width:128px;height:128px;" id="wrapper">
<img id="ico" src="https://cdn1.iconfinder.com/data/icons/windows-8-metro-style/128/mustache.png" />
</div>
和JS
$('#wrapper').draggable();
$('#ico').resizable({
aspectRatio: true,
handles: 'ne, se, sw, nw'
});
$('#c').droppable({
drop: function (event, ui) {
$('#wrapper').dblclick(function() {
var img = $('#ico');
var ctxt = $("#c")[0].getContext("2d");
var offs = $("#c").offset();
var uiPos = img.offset();
var x = uiPos.left - offs.left;
var y = uiPos.top - offs.top;
ctxt.drawImage(img[0], x, y);
$('#wrapper').remove();
});
return false;
}
});
我現在面臨的問題是,當圖像被調整它不是新加的。 這是JSFiddle http://jsfiddle.net/MZpJ6/2/中的代碼。上面的代碼是從網站的其他答案中修改的,但我不想發送其他人的問題,因此我正在創建一個新的代碼。
謝謝。
謝謝!這正是我想要實現的。 – Luchezar