set up canvas - dynamic width and height using xui.js

146 Views Asked by At

I would like to count scale of canvas but i have problem how to write it directly using xui.js - my try:

xui.extend (
{
 canvasSetup:function(scale)
 {              
var canvas = document.getElementById(x$(this));
var context = canvas.getContext('2d');

context.save();
context.translate(0, 0);

context.scale(scale, scale);
draw(context);
context.restore();
}

});

and call function like this

    x$("#canvas")
    .attr('width', cont_w + 'px')
    .attr('height', cont_h + 'px')
    ;
    x$('#canvas').canvasSetup('2'); 

I am a beginner and I have a problem with the correct code writing of this. (and also with English), so thank you very much for any help.

1

There are 1 best solutions below

0
On

this works - maybe usefull

xui.extend ({
    canvasSetup: function(id, scale){   
    var canvas = document.getElementById(id);
    var context = canvas.getContext('2d');

    context.save();
    context.scale(scale, scale);
    draw(context);
    context.restore();
    }       
    });

x$('#canvas_logo').canvasSetup('canvas_logo', 'scale_num');