1
嘿,我正在一個項目中,我需要將圖像從PC(用戶系統)拖放到html5 canvas使用fabric.js我得到了div的代碼(作爲下拉菜單)到畫布,但與PC(用戶系統)擊中畫布任何人都可以幫助我請進一步進行。將圖像從pc(用戶系統)拖放到canvas使用fabric.js
這裏是我的代碼做了迄今爲止
var js_c_drawing, activeObject = null;
$(document).ready(function() {
setDrawingCanvasCoords();
js_c_drawing = new fabric.Canvas('c_drawing');
js_c_drawing.calcOffset();
if (typeof fabric.instances != "undefined") fabric.instances.push(js_c_drawing);
});
function setDrawingCanvasCoords() {
var wHeight = $(window).height() - 100;
var wWidth = $(window).width() - 164;
var drawingStyle = 'border:4px solid gray;top:20px;position:relative;background-color:black;' + 'width:' + wWidth + 'px; height:' + wHeight + 'px';
$("#divDrawing").attr('style', drawingStyle);
}
function showToolMenu(shapeMenu) {
var divShapesId = 'divShapes';
var divElement = $('#' + divShapesId);
var ele = document.getElementById('a' + shapeMenu);
elePosition = findPos(ele);
document.getElementById(divShapesId).style.left = elePosition[0] + 'px';
document.getElementById(divShapesId).style.top = elePosition[1] + (ele.offsetHeight) + 'px';
document.getElementById(divShapesId).style.zIndex = 100;
divElement.show();
var url = baseurl + shapeMenu;
$(divElement).load(url);
}
function hideToolMenu() {
var divShapesId = 'divShapes';
var divElement = $('#' + divShapesId);
document.getElementById(divShapesId).style.zIndex = 20;
divElement.hide(2000);
}
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft, curtop];
}
我已經嘗試過使用http://www.html5rocks.com/en/tutorials/file/dndfiles/這一點,但它顯示圖像大小等,我已經試過http://jsfiddle.net/natchiketa/w8kkc/這段代碼做PC(用戶系統)和畫布但不成功。
對不起,要恢復這篇文章,但似乎它不工作了 – Lindow