English 中文(简体)
• 如何使固定参与者排在SOS键盘之上?
原标题:How to make fixed-content go above iOS keyboard?
最佳回答
问题回答

移动电话站不支持立场:在展示有重点和虚拟键盘时确定。

为了迫使其与“机动 Chrome”一样工作,你必须使用以下职位:绝对、高:整页100%,或用于你的假装元素的集装箱,拦截雕像、插头、焦点和bl。

陷阱是把所利用的投入控制放在屏幕底线,然后才能启动重点。 在这种情况下,Siper总是可以预测地浏览量和窗户。 内部 气温正变得非常明显。

开放式 in Mobile Sato to see how it work.

请避免你有几个重点内容的形式,因为需要为固定职位提供更多trick,而只是为了示范目的而增加。

请注意,对于轮换和景观模式而言,需要增加trick。 我正在制定一个称为Tuff.js的框架,该框架将提供一个完整的集装箱,帮助移动网络开发商更快地建立网络应用。 我花了将近一年的时间进行研究。

这样,在虚拟钥匙板活跃时,防止整个窗户的滚动,你就可以使用这一简单而简单的做法。

var hack = document.getElementById( scroll-hack );

function addScrollPixel() {
  if (hack.scrollTop === 0) {
    // element is at the top of its scroll position, so scroll 1 pixel down
    hack.scrollTop = 1;
  }

  if (hack.scrollHeight - hack.scrollTop === hack.clientHeight) {
    // element is at the bottom of its scroll position, so scroll 1 pixel up
    hack.scrollTop -= 1;
  }
}

if (window.addEventListener) {
  // Avoid just launching a function on every scroll event as it could affect performance. 
  // You should add a "debounce" to limit how many times the function is fired
  hack.addEventListener( scroll , addScrollPixel, true);
} else if (window.attachEvent) {
  hack.attachEvent( scroll , addScrollPixel);
}
body {
  margin: 0 auto;
  padding: 10px;
  max-width: 800px;
}

h1>small {
  font-size: 50%;
}

.container {
  display: flex;
  align-items: top;
  justify-content: space-between;
}

.container>div {
  border: #000 1px solid;
  height: 200px;
  overflow: auto;
  width: 48%;
  -webkit-overflow-scrolling: touch;
}
<h1>iOS Scroll Hack</h1>
<p>Elements with overflow:scroll have a slightly irritating behaviour on iOS, where when the contents of the element are scrolled to the top or bottom and another scroll is attempted, the browser window is scrolled instead. I hacked up a fix using minimal,
  native JavaScript.</p>
<p>Both lists have standard scrolling CSS applied (<code>overflow: auto; -webkit-overflow-scrolling: touch;</code>), but the list on the right has the hack applied. You ll notice you can t trigger the browser to scroll whilst attempting to scroll the list
  on the right.</p>
<p>The only very slight drawback to this is the slight "jump" that occurs when at the top or bottom of the list in the hack.</p>
<div class= container >
  <div id= scroll-orig >
    <ul>
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
      <li>7</li>
      <li>8</li>
      <li>9</li>
      <li>10</li>
      <li>11</li>
      <li>12</li>
      <li>13</li>
      <li>14</li>
      <li>15</li>
      <li>16</li>
      <li>17</li>
      <li>18</li>
      <li>19</li>
      <li>20</li>
    </ul>
  </div>
  <div id= scroll-hack >
    <ul>
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
      <li>7</li>
      <li>8</li>
      <li>9</li>
      <li>10</li>
      <li>11</li>
      <li>12</li>
      <li>13</li>
      <li>14</li>
      <li>15</li>
      <li>16</li>
      <li>17</li>
      <li>18</li>
      <li>19</li>
      <li>20</li>
    </ul>
  </div>
</div>

https://gist.github.com/avesus/957889b4941239490c6c441adbe32398“rel=“noreferer”>

我找到了解决这一问题的令人感兴趣的办法。

解决办法是提供隐蔽的投入,并侧重于启动活动。

<input id="backinput" style="position:absolute;top:0;opacity:0;pointer-events: none;">
<input id="input" style="position:absolute;bottom:0;">

利用JQuery:

$( #backinput ).on( focus ,function(e)
{
    e.preventDefault();
    e.stopPropagation();
    const input = document.getElementById( input );
    input.focus({ preventScroll: true });
})
$( #input ).on("touchstart", function (event) {
    if(!$(this).is(":focus"))
    {
        event.stopPropagation();
        event.preventDefault();
        $( #backinput ).focus();
    }
})

最后,重新调整观点,以便自下而上的投入在关键板上移动(如果需要的话)

window.visualViewport.addEventListener("resize", (event) => {
    $( body ).height(parseInt(visualViewport.height));
});

这对我来说是完美的。 我正在建造一个信使。

当关键板被显示或筛选时,底层推进器正在发生变化。 这不是你想要的东西,而是我能实现的最好办法。

下面请看一下我的态度及其用法。

import _ from  lodash 
import { useRef, useEffect } from  react 

export const useFixedPositionWithOpenedIOSKeyboard = (extraBottomOffset = 10) => {
  const elementRef = useRef(null)

  useEffect(() => {
    if (/iPhone|iPad|iPod/.test(window.navigator.userAgent)) {
      const setElementOffsetBottom = () => {
        const screenHeight = document.documentElement.clientHeight
        const screenHeightWithoutKeyboard = visualViewport?.height ?? 0
        const offsetTop = visualViewport?.offsetTop ?? 0

        if (elementRef?.current) {
          const elementStyles = (elementRef.current as HTMLElement).style

          if (Math.round(screenHeightWithoutKeyboard) < screenHeight) {
            elementStyles.bottom = `${
              screenHeight - screenHeightWithoutKeyboard - offsetTop + extraBottomOffset
            }px`
          } else {
            elementStyles.bottom =   
          }
        }
      }

      const debounceElementOffsetBottom = _.debounce(setElementOffsetBottom, 150)
      const showElement = () => debounceElementOffsetBottom()

      window.addEventListener( scroll , showElement)

      return () => window.removeEventListener( scroll , showElement)
    }
  }, [])

  return elementRef
}

......

export const Component = () => {
  const buttonRef = useFixedPositionWithOpenedIOSKeyboard();

  return (
    <>
      <input type= text  />
      <button type= submit  ref={button} style= 
        position: fixed;
        bottom: 40px;
        left: 50%;
        transform: translate(-50%);
        transition: bottom 0.5s cubic-bezier(0.4, 0, 0.2, 1);
       >
        This is Button
      </button>
    </>
  );
}

I adapted the whatwg s answer because it didn t work for my website (I don t know why exacly). I use the property top instead of bottom for the absolute div. My page is a chat, my div contains an input.

在此,我的解决办法是:

// Only for Safari on iOS
// (use interactive-widget=resizes-content to fix Chrome)
if (/iPad|iPhone|iPod/.test(navigator.userAgent)) {
    if (navigator.userAgent.indexOf( Chrome ) === -1 && navigator.userAgent.indexOf( Safari ) > -1) {

        // Put the body relative
        document.body.style.position =  relative ;
        let marginTop = parseInt(window.getComputedStyle(document.body).marginTop);
    
        // My toolbar (in my case, a div with an input inside to make a chat)
        myBottomDiv.style.position =  absolute ;
    
        // Events (touchmove on mobile, because the scroll event doesn t work well)
        window.addEventListener("scroll", resizeHandler);
        window.addEventListener("touchmove", resizeHandler);
        window.visualViewport.addEventListener("resize", resizeHandler);
    
        function resizeHandler() {
            myBottomDiv.style.top = (window.scrollY +  window.visualViewport.height - marginTop - myBottomDiv.offsetHeight) +  px ;
        }
    }
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签