简体   繁体   English

iOS 7 Chrome - 当弹出虚拟键盘时,固定位置抽屉不会停留在底部

[英]iOS 7 Chrome - Fixed position drawer doesn't stay at bottom when virtual keypad pops up

I have a bottom drawer which is fix positioned at the bottom. 我有一个底部抽屉,固定在底部。 When tapped, the drawer will slide up and show more content. 轻敲时,抽屉将向上滑动并显示更多内容。 On iOS 7, when user taps on input tag or textarea tag, the virtual keyboard pops up. 在iOS 7上,当用户点击输入标签或textarea标签时,会弹出虚拟键盘。 However, the drawer jumps up on the page instead of sticking to the bottom when keypad pops up. 但是,当键盘弹出时,抽屉会跳到页面上而不是粘在底部。 Please see the diagram below for illustration. 请参阅下图以获取说明。 在此输入图像描述

I firstly encountered the issue also on Safari, but I added the following code to change the fixed position to absolute when keypad is open: 我首先在Safari上遇到了这个问题,但是当键盘打开时,我添加了以下代码来将固定位置更改为绝对位置:

// Apple.Device detects if it is an apple device
if (Modernizr.touch && Apple.Device) {
    /* cache dom references */ 
    var $body = jQuery('body'); 

    /* bind events */
    $(document)
    .on('focus', 'input, textarea', function(e) {
        $body.addClass('fixfixed');
    })
    .on('blur', 'input, textarea', function(e) {
        $body.removeClass('fixfixed');
    });
} 

CSS code: CSS代码:

.fixfixed #drawer {
    bottom: 0;
    margin-left: auto;
    margin-right: auto;
    position: absolute;
    left: 0;
    right: 0;
}

This fix works on Safari on iOS 7 but it doesn't work on Chrome. 此修复程序适用于iOS 7上的Safari,但它不适用于Chrome。 Also, there is a weired behavior: 此外,还有一个令人厌倦的行为:

If there is an input tag on the page and I tap on it on iPad, then the virtual keyboard opens and the drawer jumps up. 如果页面上有输入标签,我在iPad上点击它,则虚拟键盘会打开,抽屉会跳起来。 If the drawer happens to then cover the I clicked on, the click event actually fires on the drawer. 如果抽屉恰好覆盖了我点击的那个,则点击事件实际上会在抽屉上触发。 Why is that? 这是为什么?

How can I resolve this issue? 我该如何解决这个问题? (I've been searching for a while but how do I debug Chrome on iOS?) (我一直在搜索,但如何在iOS上调试Chrome?)

Many thanks for your help! 非常感谢您的帮助!

Update 更新

I've used the following code to detect if it is Chrome on iOS 7, if so, I hide the Drawer when the virtual keyboard is up, and re-display the drawer when virtual keyboard is down. 我已经使用以下代码来检测它是否是iOS 7上的Chrome,如果是这样,我会在虚拟键盘启动时隐藏抽屉,并在虚拟键盘关闭时重新显示抽屉。

function iOSversion() {
    if (/iP(hone|od|ad)/.test(navigator.platform)) {
        // supports iOS 2.0 and later: <http://bit.ly/TJjs1V>
        var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
        return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
    }
}

var iosVersion = iOSversion();

if (navigator.userAgent.match('CriOS') && iosVersion[0] == '7') {
   $(document).hammer().on('tap', 'input, textarea', function(e) {
            $('body').addClass('chromefixfixed');
        })
            .on('blur', 'input, textarea', function(){
                body.removeClass('chromefixfixed');
            })
}

CSS code: CSS代码:

.chromefixfixed #drawer {
    display: none;
}

Still the question remains: how do I get Chrome on iOS 7 to work like Chrome on Android (without hiding the drawer when keyboard is up)? 问题仍然存在:如何让iOS 7上的Chrome像Android上的Chrome一样工作(键盘启动时不会隐藏抽屉)?

Thanks for the help! 谢谢您的帮助!

Position fixed bottom and position absolute bottom are an absolute nightmare on iOS and android devices, in my experience it's just not possible to get it to render consistently even across the most modern devices, let alone the older ones that dominate the market currently. 位置固定底部和位置绝对底部是iOS和Android设备上的绝对噩梦,根据我的经验,即使在最现代的设备上也不可能使其始终如一地呈现,更不用说当前主导市场的旧版本。 So much so, that as a dev I would ask a designer to rethink the layout because of it. 所以,作为一个开发人员,我会要求设计师重新考虑布局。 I believe it's called "sidestepping the turd". 我相信它被称为“避开粪便”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM