[removed] and scrolling on iOS 5

后端 未结 5 519
说谎
说谎 2020-11-28 02:37

iOS 5 has brought a number of nice things to JavaScript/Web Apps. One of them is improved scrolling. If you add

-webkit-overflow-scroll:touch;
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 02:55

    ScrollFix seems to be perfect solution. I tested it and it works like a charm!

    https://github.com/joelambert/ScrollFix

    /**
     * ScrollFix v0.1
     * http://www.joelambert.co.uk
     *
     * Copyright 2011, Joe Lambert.
     * Free to use under the MIT license.
     * http://www.opensource.org/licenses/mit-license.php
     */
    
    var ScrollFix = function(elem) {
        // Variables to track inputs
        var startY, startTopScroll;
    
        elem = elem || document.querySelector(elem);
    
        // If there is no element, then do nothing  
        if(!elem)
            return;
    
        // Handle the start of interactions
        elem.addEventListener('touchstart', function(event){
            startY = event.touches[0].pageY;
            startTopScroll = elem.scrollTop;
    
            if(startTopScroll <= 0)
                elem.scrollTop = 1;
    
            if(startTopScroll + elem.offsetHeight >= elem.scrollHeight)
                elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1;
        }, false);
    };
    

提交回复
热议问题