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

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

    This still seems to be plaguing webkit forms in iOS with -webkit-overflow-scrolling:touch, also in iOS 11. Based on answers above, and since it takes focusing an input or textearea element for the caret to appear out of place, here's my own approach "correcting" for it

    $('input').on("focus", function(){
        var scrollTopVal =  $(elementSelector).scrollTop();
        $(elementSelector).scrollTop(scrollTopVal + 1);
        $(elementSelector).scrollTop(scrollTopVal);
    })
    

    where elementSelector points to the container element for the input elements.

提交回复
热议问题