我使用Fabric.js来展示平面图,我使用背景图片并使用Fabric.js为电子设备添加图标,当我拖动鼠标时,只有移动的图标和背景壁纸站立那么,我怎样才能让背景移动呢?
var canvas = new fabric.Canvas('c');
canvas.selection = false;
var circle = new fabric.Circle({
radius: 20,
fill: 'green',
left: 100,
top: 100,
selectable: false
});
canvas.add(circle);
var panning = false;
canvas.on('mouse:up', function (e) {
panning = false;
});
canvas.on('mouse:down', function (e) {
panning = true;
});
canvas.on('mouse:move', function (e) {
if (panning && e && e.e) {
debugger;
var units = 10;
var delta = new fabric.Point(e.e.movementX, e.e.movementY);
canvas.relativePan(delta);
}
});
$(function () {
$('#zoomIn').click(function () {
canvas.setZoom(canvas.getZoom() * 1.1);
});
$('#zoomOut').click(function () {
canvas.setZoom(canvas.getZoom() / 1.1);
});
});