Jquery阻止设备键盘重新调整浏览器内容的大小

时间:2014-04-10 21:05:57

标签: javascript android jquery jquery-mobile keyboard

我的网站可以扩展所有内容以适应用户的移动设备屏幕。但是当启动默认键盘时,整个站点将被重新调整。可以让键盘覆盖网站,以免扭曲网站或缩放并专注于用户触摸的特定输入字段。

what it should like 这就是我认为会发生的事情或非常相似的效果。

但这就是正在发生的事情 enter image description here

右边的内容保持不变。这有一个固定的宽度,但定位适合:

top:0px;
bottom:0px;
left:0px;

页面在页面加载时调整大小和缩放。这些是设定的高度和宽度。例如,如果高度为600px,那么宽度将为800px。

    var windowWidth = parseInt(window.innerWidth);
    var windowHeight = parseInt(window.innerHeight);    
    //set content height 90% of windowHeight
    var c_height = windowHeight / 100 * 95;
    var c_width = c_height * 1.48;
    $('#content').css('height',c_height+'px');
    $('#content').css('width',c_width+'px');

我遇到过类似的事情,但没有成功:

function updateViews() {
    $('#page').hide();
    if (is_keyboard) {
        $("#page").hide();
    }
    else {
        $('#page').show();
    }
}
window.addEventListener("resize", function() {
    is_keyboard = (window.innerHeight < initial_screen_size);
    is_landscape = (screen.height < screen.width);

    updateViews();
}, false);
/* iOS */
$("input").bind("focus blur",function() {
    $(window).scrollTop(10);
    is_keyboard = $(window).scrollTop() > 0;
    $(window).scrollTop(0);
    updateViews();
});

我认为这件事会被设备默认。

更新: 如果它有助于所有页面内容都包含在div中;

<div id="body" style="width:100%; height:100%;">

键盘也不会打开任何其他输入,只有顶部的栏。

1 个答案:

答案 0 :(得分:2)

尝试这一点,我正在开发移动设备,我的页面已修复,因此可能会有效。

<div id="body" style="width:100%; height:100%; position: fixed">
相关问题