html - 在 Chrome 中调整大小时,游戏 Canvas 不适合整个页面

标签 html css google-chrome cocos2d-js

我创建了一个 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>

如您所见,我将其设置为 Canvas 适合整个页面。这是游戏的外观(默认为 500x500):

enter image description here

如果我调整窗口大小, Canvas 通常会正确调整大小。但有时它会有某种排序或余量:

enter image description here

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

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

我正在使用 Mac OSX Yosemite。

最佳答案

尝试:

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

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

关于html - 在 Chrome 中调整大小时,游戏 Canvas 不适合整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32488480/

相关文章:

javascript - Chartist.js 在 vue.js 中显示工具提示

javascript - 具有绝对定位的可滚动div

html - 如果我使用 FontAwesome,它会影响 SEO 吗?

html - 我的 Chrome 扩展程序中的 "Unknown error"

google-chrome - 谷歌浏览器无法检测到 v4l2loopback 设备

javascript - 当输入改变时Jquery触发不起作用

php - 如何在一个程序中读取和写入php套接字?

javascript - 集成 VIN 解码器 API

html - 在列内的右下角放置一个 div

javascript - React 组件未显示在浏览器上,出现空白屏幕