最近一直再找工作,也好久没有更新博客。。。。  

  之前遇到一个问题,就是在手机上点击input框的时候,发现有的时候就是不自动滑动到相应的位置,怎么兼容这个奇葩的手机呢?

  其实这类问题,只要懂他们的原理话,就很容易解决了。

  原理:当你点在foucs上面计算需要滑动的位置

  解决方式:

// Android 手机下, input 或 textarea 元素聚焦时, 主动滚一把
if (/Android/gi.test(navigator.userAgent)) {
    window.addEventListener('resize', function () {
      if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {
          window.setTimeout(function () {
         document.activeElement.scrollIntoViewIfNeeded(); },
0); } }) }

 

相关文章:

  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-01-05
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-05-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案