为什么画布上下文不能写入函数内部?

时间:2018-06-13 11:07:10

标签: javascript jquery html html5

我有一个用于收集用户签名的画布。线的厚度必须根据片剂的方向而改变。当这个脚本执行时,我希望线条的粗细为6或10,但它仍然是默认值1.有人能够解释为什么吗?

var canvas = $("#signature_canvas")[0];
var context = canvas.getContext("2d");
var pendown = false;

function resize_canvas(){
    if(screen.height > screen.width){
        context.lineWidth = 6;
        canvas.width = screen.width;
        canvas.height = (screen.width / screen.height) * screen.width;
    }else{
        context.lineWidth = 10;
        canvas.width = screen.width;
        canvas.height = screen.height;
    }
};
resize_canvas();
console.log(context.lineWidth);

0 个答案:

没有答案