fabricjs - fabric canvas on top of another canvas -
is there way have 2 fabricjs canvases 1 top of each other? want able draw on both canvases, want lines contained on canvas top. canvas bottom have labels not able drawn on canvas top.
crude image of i'm trying go for
i thought layer 2 canvases together, 1 on top of using css:
<style> .div { width: 1550px; height: 512px; border: solid 0px #4a7497; margin-top: -512px; margin-left: 100px; position: relative; } </style> <canvas id="canvasbottom" width="1650" height="612"</canvas> <canvas id="canvastop" class="div" width="1550" height="512"></canvas>
my script renders bottom canvas. @ point, want display both canvases have lines on canvas top.
<script type="text/javascript"> $( document ).ready(function() { var canvasbottom = new fabric.canvas('canvasbottom', { selection: false, backgroundcolor: 'black', targetfindtolerance: 20}); var canvas = new fabric.canvas('canvastop', { selection: false, backgroundcolor: 'white', targetfindtolerance: 20}); canvas.setbackgroundimage('http://website/image/background.png', canvas.renderall.bind(canvas)); var grid = 15; var d = document, ge = 'getelementbyid'; //draws vertical lines (var = 1; <= (<?php echo $ylines; ?>); i++) { canvas.add(new fabric.line([ * grid+100, 0, * grid+100, 612],{stroke: 'yellow',strokewidth: 1})); } canvas.renderall(); canvasbottom.renderall(); }); </script>
as shared information how put layers using css stackoverflow post: https://stackoverflow.com/a/3008863/7132835 need same logic, in addition need add code below fabric canvas declaration:
var canvasbottom = new fabric.canvas('layer1',{position: absolute}); var canvas = new fabric.canvas('layer2',{position: absolute});
you can add additional properties background, etc.
Comments
Post a Comment