【问题标题】:Game canvas is not fitting the whole page when resized in Chrome在 Chrome 中调整大小时,游戏画布不适合整个页面
【发布时间】:2015-09-09 20:21:40
【问题描述】:

我创建了一个 cocos2d-javascript 游戏,并正在 Chrome 上对其进行测试。网页的 HTML 是

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Testing</title>
    <link rel="icon" type="image/GIF" href="res/favicon.ico"/>
    <meta name="viewport" content="width=100%, initial-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="full-screen" content="yes"/>
    <meta name="screen-orientation" content="landscape"/>
    <meta name="x5-fullscreen" content="true"/>
    <meta name="360-fullscreen" content="true"/>
    <style>
        body, canvas, div {
            -moz-user-select: none;
            -webkit-user-select: none;
            -ms-user-select: none;
            -khtml-user-select: none;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            width: 100%;
            height: 100%;
            margin: 0px;
        }
    </style>
</head>
<body style="padding:0; margin: 0; background: #000; width:100%; height:100%; margin: 0px;">
<script src="res/loading.js"></script>
<canvas id="gameCanvas" width="100%" height="100%"></canvas>
<script src="frameworks/cocos2d-html5/CCBoot.js"></script>
<script cocos src="main.js"></script>
</body>
</html>

如您所见,我设置它以使画布适合整个页面。这就是游戏的外观(默认为 500x500):

如果我调整窗口大小,画布通常会正确调整大小。但有时会有某种排序或边距:

怎么了?我想问题是 HTML 本身,而不是 cocos2d。

这似乎只发生在 Chrome 上。 Firefox 看起来不错。

我正在使用 Mac OSX Yosemite。

【问题讨论】:

    标签: html css google-chrome cocos2d-js


    【解决方案1】:

    试试:

    *, html {
    margin:0 !important;
    padding:0 !important;  
    }
    

    我建议删除 body style 属性内的属性(只是为了清洁),并在 head 内仅保留 style 标签内的属性。

    【讨论】:

    • 嗯,运气不好,但似乎确实有所改善。现在从来没有填充左侧。唯一的问题是底部和右侧。
    • 我通过添加width:100% !important; height:100% !important;得到它的工作
    猜你喜欢
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 2014-05-07
    • 2018-06-27
    • 2014-06-20
    相关资源
    最近更新 更多