Draw2D设置位置

Draw2D Set Position

本文关键字:位置 设置 Draw2D      更新时间:2023-09-26

我是这个库的新手,似乎找不到任何关于如何调整画布大小和位置的详细信息。希望这里有人能告诉我如何定位画布

   $(window).load(function () {

    // create the canvas for the user interaction
    //
    var canvas = new draw2d.Canvas("gfx_holder");
    // unmarshal the JSON document into the canvas
    // (load)
    var reader = new draw2d.io.json.Reader();
    reader.unmarshal(canvas, jsonDocument);
    // display the JSON document in the preview DIV
    //
    displayJSON(canvas);
    // add an event listener to the Canvas for change notifications.
    // We just dump the current canvas document into the DIV
    //
    canvas.getCommandStack().addEventListener(function (e) {
        if (e.isPostChangeEvent()) {
            displayJSON(canvas);
        }
    });
});
function displayJSON(canvas) {
    var writer = new draw2d.io.json.Writer();
    writer.marshal(canvas, function (json) {
        $("#json").text(JSON.stringify(json, null, 2));
    });
}

"gfx_holder"是HTML元素的id。你可以使用常规的JavaScript设置宽度和高度。