iPhone Web App - Stop body bounce/scrolling in iOS8

前端 未结 3 1057
时光说笑
时光说笑 2021-02-02 00:59

Yes, I know. This question has been asked a thousand times before. Thanks to all you guys, I was able to find a solution that finally did the job for me in <= iOS7. However,

3条回答
  •  清歌不尽
    2021-02-02 01:35

    So this has been bothering me for ages too and I finally found a solution!

    Pre iOS8, Safari has no subpixel rendering. Now that there is subpixel rendering, the reported element height is given as the subpixel decimal, and the scroll height is the actual rendered integer heigh. If you specify sizes in percent, this can result in the height being a fraction of a pixel smaller than it should be.

    Instead of testing for

    if (elem[0].scrollHeight > height) {
                        e.stopPropagation();
    }
    

    Testing for this will give you the rounded number that matches up.

    if (elem[0].scrollHeight > Math.ceil(height)) {
                        e.stopPropagation();
    }
    

提交回复
热议问题