html5 网页宽度100,HTML5 Canvas 100%视口宽度?

f681014429385610e430323e203a2213.png

PIPIONE

为了使画布全屏宽度和高度始终如此,即使在调整浏览器大小时,也需要在将画布大小调整为window.innerHeight和window.innerWidth的函数中运行绘制循环。示例:http://jsfiddle.net/jaredwilli/qFuDr/HTMLJavaScript的(function() {

    var canvas = document.getElementById('canvas'),

            context = canvas.getContext('2d');

    // resize the canvas to fill browser window dynamically

    window.addEventListener('resize', resizeCanvas, false);

    function resizeCanvas() {

            canvas.width = window.innerWidth;

            canvas.height = window.innerHeight;

            /**

             * Your drawings need to be inside this function otherwise they will be reset when 

             * you resize the browser window and the canvas goes will be cleared.

             */

            drawStuff(); 

    }

    resizeCanvas();

    function drawStuff() {

            // do your drawing stuff here

    }})();CSS* { margin:0; padding:0; } /* to remove the top and left whitespace */html, body { width:100%; height:100%; } /* just to be sure these are full screen*/canvas { display:block; } /* To remove the scrollbars */这就是你如何正确地使画布的全宽和高度的浏览器。您只需将绘制的所有代码放入drawStuff()函数中的画布。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值