[removed] and scrolling on iOS 5

后端 未结 5 527
说谎
说谎 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:57

    The only issue with Brian Nickel's answer is that (as user1012566 mentioned) stopPropagation doesn't prevent bubbling when you hit your scrollable's boundaries. You can prevent this with the following:

    elem.addEventListener('touchstart', function(event){
        this.allowUp = (this.scrollTop > 0);
        this.allowDown = (this.scrollTop < this.scrollHeight - this.clientHeight);
        this.prevTop = null; 
        this.prevBot = null;
        this.lastY = event.pageY;
    });
    
    elem.addEventListener('touchmove', function(event){
        var up = (event.pageY > this.lastY), 
            down = !up;
    
        this.lastY = event.pageY;
    
        if ((up && this.allowUp) || (down && this.allowDown)) 
            event.stopPropagation();
        else 
            event.preventDefault();
    });
    

提交回复
热议问题