Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrollTop的bug #16

Open
wangbagang opened this issue Sep 13, 2016 · 0 comments
Open

scrollTop的bug #16

wangbagang opened this issue Sep 13, 2016 · 0 comments

Comments

@wangbagang
Copy link

wangbagang commented Sep 13, 2016

当我手动滑动的距离大于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()
})`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant