我有帆布化妆画布高度自动
<canvas id="canvas" width="1700" height="679" style="background-color:#ffffff;width:100%;overflow:hidden;margin-top: -7px;"></canvas>
它工作于Chrome和Firefox的罚款。然而,也就是可以用宽度只工作:100%,但不改变其高度(上679高度)
我试着高度为汽车和100%,但得到wose
编辑:终于来了!我知道了。确实,画布的内容在宽度100%上不会很好。 然而,对于高度(IE9以上工作),你必须设置高度风格
$("#canvas").attr('style','background-color:#ffffff; width:100%;height:679px;overflow:hidden;margin-top: -7px;');
而且使用jQuery重新大小重新大小的窗口画布
function resizeIE()
{
canvas = document.getElementById("canvas");
if($.browser.msie) //only IE
{
$("#canvas").attr('style','background-color:#ffffff; width:100%;height:679px;overflow:hidden;margin-top: -7px;');
//set the height style first
if(window.innerWidth<960) //for other device (only for me)
{
var height_ie = (window.innerWidth*39.941176470588235294117647058824)/100;
//to make the ratio of canvas find the pencentage
//ex. canvas height: 1700px canvas width: 679px;
//(679*100)/1700 = 39.941 <-- use this one
//best solution
}
else
{
var height_ie = window.innerHeight-160; //just for the logo for my web
}
canvas.style.height = height_ie+"px";
}
}
适用于文件。准备好
window.onresize = function(event) {
resizeIE();
};
使用CSS,你可以不适用高度? – sajay
@sajay我添加CSS内联画布到高度:100%和高度:自动。结果是更小,并保持不变,当调整大小 – user1128331
谢谢你推荐使用CSS :) – user1128331