Mobile Safari - Input caret does not scroll along with overflow-scrolling: touch

后端 未结 10 2299
攒了一身酷
攒了一身酷 2020-12-25 15:24

I know that Mobile Safari won\'t fire events while in \"momentum\" (-webkit-overflow-scrolling: touch;) scrolling. But this is not entirely the same thing, because Safari ha

10条回答
  •  盖世英雄少女心
    2020-12-25 15:44

    Only one workaround that I was found - on scrolling event to check if input with type text is focused, set focus on some other element (for example, on button). As result, virtual keyboard and cursor will disappear. This solution is not perfect, but it doesn't look so horrible as with cursors on top of the form. Example:

    $(".scrollContainer").scroll(function () {
      var selected = $("input[type='text']:focus");
      if (selected.length > 0) {
          $('#someButton').focus();
      }
    }
    

提交回复
热议问题