cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.81k forks source link

Iscroll inside Iscroll #392

Open jnurse13 opened 11 years ago

jnurse13 commented 11 years ago

Situation I have a one main div holding a series of small divs, (think widgets on a dash board). Some of the small divs need Iscroll to scroll the information. The large div or page also has Iscroll. When I scroll using touch or mouse wheel over a small div the, it scroll but the scroll is passed through to large div behind, so both scroll. How can I stop this?

garciaalvaro commented 11 years ago

I made a jsFiddle that displays the scrollEnd and scrollStart of nested iscrolls. http://jsfiddle.net/z8TKL/

cubiq commented 11 years ago

at the moment iscroll is not really done for nesting :) I'll work on it for future releases

mellinger commented 11 years ago

Putting e.stopPropagation(); somewhere near line 354, inside the start function, seems to do the trick for me :)

pnchen commented 11 years ago

Hope the mouse event been passed as a parameter during the scroll notification(like iscroll4 onScrollStart...), so that I can control the event propagation myself.

cubiq commented 11 years ago

@pnchen click can be fired with click:true option

jtwee commented 11 years ago

I did this in a rather hacky way by enabling/disabling the parent scroller on touchstart/touchend of the inner. To do so I had to have globally accessible iscroll instance variables (an array called pageScrollers in my case), but I needed those for other things anyway. YMMV.

$('.iScroller .inline-scroller').on({
    touchstart: function() {
        if (pageScrollers[currentPageID]) {
            pageScrollers[currentPageID].disable();
        }
    },
    touchend: function() {
        if (pageScrollers[currentPageID]) {
            pageScrollers[currentPageID].enable();
        }
    }
});
jhnns commented 11 years ago

Seems like nesting iScroll is very common :wink:

johannesjo commented 10 years ago

This is working now, isn't it? At least for 2 elements if you have one for the vertical axis and one for the horizontal axis. Imho everything else doesn't make much sense anyway.

jasokant commented 10 years ago

@breams I adapted your workaround a little, adding mouseup and mousedown events like so...works great for my needs:

$('.iScroller .inline-scroller').on({
    touchstart: function() {
        if (pageScrollers[currentPageID]) {
            pageScrollers[currentPageID].disable();
        }
    },
    mousedown: function() {
        if (pageScrollers[currentPageID]) {
            pageScrollers[currentPageID].disable();
        }
    },
    touchend: function() {
        if (pageScrollers[currentPageID]) {
            pageScrollers[currentPageID].enable();
        }
    },
    mouseup: function() {
        if (pageScrollers[currentPageID]) {
            pageScrollers[currentPageID].disable();
        }
    }
});
krnlde commented 10 years ago

Any news on this?

Linrstudio commented 9 years ago

mark

nickizzle commented 9 years ago

It would be incredibly useful to get this fixed. breams solution works OK to prevent the parent scrolling while scrolling a child scroller, but it would be nice if once you get to the top of a child scroller, the parent automatically starts scrolling up again (likewise with the bottom)

fgilio commented 9 years ago

Thanks @jasokant, it worked great! It would be really nice to have this fixed, with the functionality @nickizzle mentioned

nickizzle commented 9 years ago

This is the solution I came up with in the end. @fgilio you may find this useful. In this example, innerScroll and outerScroll are both iScrolls. innerScroll is inside outerScroll:

innerScroll.on('scrollStart', function() {
    if ((this.y < 0 && this.directionY == -1) || (this.y > this.maxScrollY) && this.directionY == 1) {
        outerScroll.disable();
    }
});
innerScroll['js-terms-scroll'].on('scrollEnd', function() {
    outerScroll.enable();
});
fgilio commented 9 years ago

Thanks @nickizzle, that's pretty useful!!

sandor commented 8 years ago

Hey Guys,

how could be this fiddle be achieved with iScroll5?

http://jsfiddle.net/khaledalyawad/4p7t8ymp/

I am having problems to implement the solution of @nickizzle

THX!

ganya-qwe commented 7 years ago

@nickizzle i don't know how you become this code working for iscroll. Iscroll doesn't use native scroll, it change position of content inside parent container via transform. I can realize only @breams code