xscroll icon indicating copy to clipboard operation
xscroll copied to clipboard

scrollTop的bug

Open wangbagang opened this issue 9 years ago • 0 comments

当我手动滑动的距离大于50px的时候,监听panend调用xscroll.scrollTop('-' + 400, 400, 'ease-in-out')以后,再次触摸的时候会跳一下,查看源码得知: if (boundryCheck) { //over top y = y > boundry.top ? bounce ? (y - boundry.top) * PAN_RATE + boundry.top : boundry.top : y; //over bottom y = y < boundry.bottom - containerHeight ? bounce ? y + (boundry.bottom - containerHeight - y) * PAN_RATE : boundry.bottom - containerHeight : y; //over left x = x > boundry.left ? bounce ? (x - boundry.left) * PAN_RATE + boundry.left : boundry.left : x; //over right x = x < boundry.right - containerWidth ? bounce ? x + (boundry.right - containerWidth - x) * PAN_RATE : boundry.right - containerWidth : x; } 在这里判断有问题。boundry的值是触摸的位置,应该是scrollTop最后的位置,所以导致会跳一下。希望解决,下面是我的代码 ` var xscroll = new XScroll({ renderTo:"#dayContainer", lockY:false, scrollbarY:false }); xscroll.render(); xscroll.on('scroll', function (scroll) { $('.history-cala').css({ opacity: Math.abs(scroll.scrollTop/$('.history-cala').outerHeight(true)) }) })

var startY = 0;
xscroll.on('panend', function (e) {
    var top = xscroll.getScrollTop();
    var diff = top - startY;
    console.log(diff + '...' + top)
    if(Math.abs(diff) > 30){
        if(diff < 0){
            xscroll.scrollTop('-' + $('.history-cala').outerHeight(true), 400, 'ease-in-out')
        } else {
            xscroll.scrollTop(0, 400, 'ease-in-out')
        }
        setTimeout(function () {
            xscroll.init()
        }, 400)
    }
})

xscroll.on('panstart', function (e) {
    startY = xscroll.getScrollTop()
})`

wangbagang avatar Sep 13 '16 09:09 wangbagang