我想通過自己的ID刪除帆布我試着給它們分配ID可以調用刪除方法,但它不工作:無法刪除帆布和變化SRC通過其ID:面料JS
見鏈接:http://jsfiddle.net/mishragaurav31/kcyKJ/
的html代碼:
刪除itchange它
js代碼
var canvas = new fabric.Canvas('c');
function getObjectById(id) {
canvas.forEachObject(function(o) {
if (o.id === id) {
return o;
}
});
return null;
}
var img = "http://edudemic.com/wp-content/uploads/2012/09/jail_photo.jpg";
fabric.Image.fromURL(img, function (source) {
img = source.set({
left: 0,
top: 0,
angle: 0,
id:'moveit'
});
canvas.add(img);
canvas.renderAll();
});
document.getElementById('download').onclick = function() {
alert('hii');
var removeit = getObjectById('moveit');
canvas.remove(removeit);
};
document.getElementById('changeimage').onclick = function() {
alert('hii');
getObjectById('moveit').src="http://www.meandmylaptop.com/uploads/5/8/1/2/5812329/7801574.png";
canvas.renderAll();
};
document.getElementById('changeimage').onclick = function() {
alert('hii');
getObjectById('moveit').src="http://www.meandmylaptop.com/uploads/5/8/1/2/5812329/7801574.png";
canvas.renderAll();
};
'變種removeit = getObjectById( 'moveit');'爲空。所以不知何故,你設置的ID,但ID沒有被應用。 – artm 2014-10-17 09:55:07
如何設置id? – mydeve 2014-10-17 10:13:56