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

后端 未结 10 2298
攒了一身酷
攒了一身酷 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:50

    You can fix the problem by removing the selection and setting it again. Using jQuery here is the Javascript to do so. I add the event handler when entering edit mode:

            $(document).on('scroll.inline-edit', function(event) {
                var selection = window.getSelection();
                if (selection.rangeCount) {
                    var range = selection.getRangeAt(0);
                    selection.removeAllRanges();
                    selection.addRange(range);
                }
            });
    

    When I exit edit mode I remove the event handler:

            $(document).off('scroll.inline-edit');
    

    This will probably also work if the event handler is always enabled.

提交回复
热议问题