可以用JS监控屏幕大小,然后调整Canvas的大小。在代码中加入JS
$(window).resize(resizeCanvas);
function resizeCanvas() {
canvas.attr("width", $(window).get(0).innerWidth);
canvas.attr("height", $(window).get(0).innerHeight);
context.fillRect(0, 0, canvas.width(), canvas.height());
};
resizeCanvas();
注意:$(window).get(0)是将jQ转成js来写,jQ和js不能混合来用的!!!