I trying let the responsive canvas following this topic1 and topic2
I'm trying to let the responsive canvas for all devices.
I know it's possible but I'm having a tough time finding the solution.
Following the two topics above I tried to set the width and height for the max canvas size in javascript. And in the css for each device a different size to canvas view, even changing the CSS display size actual size defined in javascript must remain
I´m using fabric.js
SOLUTION
Note: stack Overflow view considering width 360px because of the preview in the post
var canvas = this.__canvas = new fabric.StaticCanvas ('c');
canvas.setHeight(600);
canvas.setWidth(800);
canvas.setBackgroundImage('http://lorempixel.com/500/500/animals', canvas.renderAll.bind(canvas), { width: 800,height: 600 });
var text = new fabric.Text('Hello', { left: 100, top: 100, fill: 'blue', });
canvas.add(text);
#c{
border:1px solid red;
top:22px;
left:0px;
height: 100%;
width: 99%;
}
@media screen and (min-width: 360px) {
#c { -webkit-transform : scale(0.4);
-webkit-transform-origin : 0 0; }
}
@media screen and (min-width: 768px) {
#c { -webkit-transform : scale(0.45);
-webkit-transform-origin : 0 0; }
}
@media screen and (min-width: 992px) {
#c { -webkit-transform : scale(0.5);
-webkit-transform-origin : 0 0;}
}
@media screen and (min-width: 1200px) {
#c { -webkit-transform : scale(0.5);
-webkit-transform-origin : 0 0;}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.5.0/fabric.js"></script>
<canvas id="c"></canvas>