简体   繁体   English

移动键盘上方的位置元素

[英]Position element above mobile keyboard

I'm trying to position an element directly above a mobile keyboard.我正在尝试将元素直接放置在移动键盘上方。 ie: position absolute/fixed to bottom of page, but pushed up by the keyboard (or pushed up equivalent height of the keyboard).即:绝对位置/固定到页面底部,但被键盘向上推(或向上推键盘的等效高度)。

Usually this is the opposite behavior of what's desired, and there's to be a lot of people fighting to keep bottom elements in place.通常这是与所期望的相反的行为,并且会有很多人为保持底部元素而奋斗。 I feel like I remember fighting those same battle before...我觉得我记得以前打过同样的战斗......

But now that I want it to move, it's not.但现在我想让它移动,它不是。 (of course!) (当然!)

My focus is iOS Safari for now, but would prefer cross browser.我现在的重点是 iOS Safari,但更喜欢跨浏览器。

It seems older versions of iOS changed window.innerHeight when the keyboard opened, for better or worse.似乎旧版本的 iOS 在键盘打开时更改了window.innerHeight ,无论好坏。 But that's no longer the case.但情况已不再如此。 Which may explain why I'm not seeing what I expected to see...这可以解释为什么我没有看到我期望看到的......

I've been playing around with variously positioned parent elements with no luck.我一直在玩各种定位的父元素,但没有运气。

Is this even possible?这甚至可能吗? Or is the keyboard now completely detached from the viewport?还是键盘现在完全脱离了视口?

It is not possible.这不可能。 The keyboard appears to be its own entity away, or as you said, detached from the viewport.键盘似乎是它自己的实体,或者如您所说,与视口分离。

Although you can't fix the element to the keyboard exactly, might I suggest that you may be able to use JavaScript and add a class that raises the fixed element the same height as the keyboard.尽管您无法将元素完全固定到键盘上,但我建议您可以使用 JavaScript 并添加一个类,将固定元素提升到与键盘相同的高度。

The keyboard sizes can be found here: What is the height of iPhone's onscreen keyboard?可以在此处找到键盘尺寸: iPhone 屏幕键盘的高度是多少?

It's possible withVisualViewport API now to listen for the viewport change and read it values.现在可以使用VisualViewport API 来监听视口变化并读取它的值。 In practice, it's not sending events immediately so the experience might be laggy.实际上,它不会立即发送事件,因此体验可能会滞后。

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

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