javascript - 横向显示键盘时 HTML Canvas 中断

标签 javascript android css html canvas

已尝试列出所有这些问题和答案,但对我没有任何帮助!

How to center canvas in html5 Resize HTML5 canvas to fit window

HTML5 Canvas 100% Width Height of Viewport?

Make canvas fill the whole page

Make Html5 Canvas and Its contained image responsive across browsers

jQuery to make HTML5 Canvas Responsive

How to make canvas responsive according to the div parent width



就是这样,

我在玩 html canvas,它在我的电脑、手机和平板电脑上运行良好。我正在处理的代码,
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>Area52</title>
    <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
    <style>
    body{
        padding: 0;
        margin: 0;
    }
    .container{
        position: absolute;
        z-index: 0;
    }
    canvas { 
        display: block;
        height: 100%; 
        width: 100%; 
    }

    .details{
        color: #fff;
        top: 150px;
        padding: 20px;
        position: relative;
        z-index: 10;
        font-family: Roboto;
        height: 20px;
    }
    </style>
</head>
<body>
<div class="container">
    <canvas id="myCanvas" style="border:1px solid #000000; background: url('http://upload.wikimedia.org/wikipedia/commons/6/64/The_Puppy.jpg');background-attachment: fixed;background-size: cover;">
    </canvas>
</div>

<div class="details">
    Enter your details:
    <form>
      First name: <input type="text"><br>
      Last name: <input type="text"><br>
      <input type="submit">
    </form>
</div>
</body>
</html>

当平板电脑的方向改变并尝试在文本框中输入一些文本时, Canvas 元素的大小会调整为奇怪的东西。

截图:

on tablet portrait

1.竖屏模式下,键盘为shown时, Canvas 缩小到视口(viewport)高度!

on tablet landscape

2.在横向模式下, Canvas 渲染良好,

on tablet landscape with keyboard on

3.横屏模式下,键盘为shown时 Canvas 缩小到奇怪的东西!

如何修复按下键盘时重新调整 Canvas 大小的问题 on .

环境:Android 5.1.1 上的 Chrome 42.0.x

谢谢
PS:背景图只是演示用,实际方案是canvas和graphic。

最佳答案

尝试使用固定位置:

canvas { 
    position: fixed;
    left:0;
    top:0;
    height: 100%; 
    width: 100%;
    z-index: -1;  /* place in background */
}

关于javascript - 横向显示键盘时 HTML Canvas 中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30655531/

相关文章:

javascript - 将 url 与变量中的文本进行比较

android - 静态类变量的生命周期

android - Facebook 登录安卓

javascript - 使用css3在图像上生成轮廓效果

jquery - Ennui : how to keep navigation arrows visible 的内容 slider

javascript - 将点击设置为未创建的元素

javascript - 我的 React Pagination 工作得很好,但搜索功能却不行?

javascript - 提交表单后防止重新加载页面。 (没有 Ajax )

java - 使用 http-post 和 AsyncTask 将数据插入 MySQL 不起作用

html - 在html中定位元素有困难