简体   繁体   中英

disabling horizontal robber banding effect using jquery

i am trying to disable horizontal scroll in an webapp and so far no luck... i have no idea what to do right now...been stuck for awhile now !! anyone has any idea on any possible solutions?!

I used this to disable the vertical one

$('body').on('touchstart','.menuScrolling',function(e) 
{
    if (e.currentTarget.scrollTop === 0) 
    {
        e.currentTarget.scrollTop = 1;
    } 
    else if (e.currentTarget.scrollHeight === e.currentTarget.scrollTop + e.currentTarget.offsetHeight) 
    {
        e.currentTarget.scrollTop -= 1;
    }
});

and i thought maybe if i change a few variables it should work for horizontal too but nop..

$('body').on('touchstart','.menuScrolling',function(e) 
{
    if (e.currentTarget.scrolLeft === 0) 
    {
        e.currentTarget.scrolLeft = 1;
    } 
    else if (e.currentTarget.scrollHeight === e.currentTarget.scrolLeft + e.currentTarget.offsetWidth) 
    {
        e.currentTarget.scrolLeft -= 1;
    }
});

You're missing an L

e.currentTarget.scrolLeft

to

e.currentTarget.scrollLeft

Please post a fiddle of your code. I will edit my answer to try and help you further.

One idea that came to mind is this (I assume you are supporting only touch devices for this, correct?):

$('body').bind ('touchmove', function(e) {
    e.preventDefault();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM