从Javascript设置画布属性失败

gc5*_*gc5 1 javascript jquery height canvas width

我必须为canvas元素设置属性'width'和'height',具体取决于可用的屏幕分辨率.从html中静态设置它们(例如<canvas id="canv" width="1600" ...).从Javascript我不能这样做.我用谷歌搜索和搜索,但我找不到任何有用的东西.我正在使用JQuery,我尝试了以下不成功(高度属性相同)

$('#canv').setAttribute('width',screen.availWidth);
$('#canv').attr('width',screen.availWidth);
$('#canv').data('width',screen.availWidth);
$('#canv').width = screen.availWidth;
$('#canv').css('width',screen.availWidth);
Run Code Online (Sandbox Code Playgroud)

我做了相同的推杆var cv = $('#canv')[0].getContext("2d");和改变$('#canv'),cv但没有结果.

BB

Cas*_*nge 7

我将jsfiddle.net/pUcjV/2上的代码更改

$('#canv').attr("width", screen.availWidth);    
$('#canv').attr("height", screen.availHeight);  
circlesBG (cv, col, screen.availWidth, screen.availHeight);
Run Code Online (Sandbox Code Playgroud)

circlesBG (cv, col, screen.availWidth, screen.availHeight);
$('#canv').width(screen.availWidth);    
$('#canv').height(screen.availHeight);    
Run Code Online (Sandbox Code Playgroud)

这在整个画布上产生了星星.这是期望的结果吗?我正在使用Chrome 5.0.375.99.