2

在下面的代码中,我添加了三个注释来解释问题所在。简而言之:我想知道e.preventDefault();当它已经设置时如何禁用?

   var startY;
   myScroll = new iScroll(DOMElement, {
        snap: 'li',
        bounce: false,
        bounceLock: false,
        momentum: false,
        hScrollbar: false,
        vScrollbar: false,
        hScroll: true,
        vScroll: false,
        wheelAction: 'scroll',
        onBeforeScrollStart: function(e){
            startY = e.pageY;
            // By default it's advisable to disable browser's scroll
            e.preventDefault();
        },
        onScrollStart: function(){  },
        onScrollMove: function(e){
            // But here I want to enable browser's functionality if user
            // explicitly demands this (i.e. tries to scroll vertically)
            if(startY >= e.pageY+70 || startY <= e.pageY-70){
                console.log('test');
                //alert('test');
                console.log(e);
                // However, I don't know how to restore this functionality
                // Touch device detects 'test' alert correctly and this is
                // where I'm stuck.
            }
        },
        onScrollEnd: function(){ },
        onRefresh: function(){ },
        onDestroy: function(){ },
    });

任何帮助,将不胜感激!

4

1 回答 1

2

您可以控制滚动onBeforeScrollStart。防止在特定区域之间滚动。如果超过,滚动开始。我认为这有帮助:

var startY;
var isStarted = false;
myScroll = new iScroll(DOMElement, {
    snap: 'li',
    bounce: false,
    bounceLock: false,
    momentum: false,
    hScrollbar: false,
    vScrollbar: false,
    hScroll: true,
    vScroll: false,
    wheelAction: 'scroll',
    onBeforeScrollStart: function(e){
        var y=e.pageY;
        if (!isStarted) {
            startY = y + 0;
            isStarted = true;
        }

        if(startY < y+70 || startY > y-70){
            e.preventDefault();
        }
    },
    onScrollStart: function(){  },
    onScrollMove: function(e){ },
    onScrollEnd: function(){
        isStarted = false;
    },
    onRefresh: function(){ },
    onDestroy: function(){ },
});
于 2013-04-18T16:19:46.533 回答