Materialize: Carousel prevent the scroll up and scroll down of the containing page.

Created on 27 Mar 2017  路  17Comments  路  Source: Dogfalo/materialize

Description

The swipe up or swipe down events within the carousel are not propagating.
Carousel should handle only swipe left and swipe right events and don't impact to the the vertical scrolling of the containing page.

Repro Steps

Open the documentation for th carousel component with a mobile device and try to scroll down or up the page starting the scroll from the carousel component.

bug Carousel

Most helpful comment

The handling of the touchstart event seems to prevent vertical scrolling.

```javascript
function tap(e) {
e.preventDefault();
...
}
````
Why do we want to prevent default behaviour for this event? Any chance we can remove this line?

All 17 comments

We have to filter the swipe up and swipe down events of Hammer.js, I will prepare a PR for this.

Duplicate of https://github.com/Dogfalo/materialize/issues/3881

I think that we can't prevent the page scrolling when using the carousel from touch devices.
This is annoying when the carousel content fit the height of the device screen

The carousel currently does this, but the threshold for the horizontal movement is pretty low, so a downward angled swipe will often be misinterpreted as horizontal movement

Great , why don't we increase the threshold providing an option ?

The handling of the touchstart event seems to prevent vertical scrolling.

```javascript
function tap(e) {
e.preventDefault();
...
}
````
Why do we want to prevent default behaviour for this event? Any chance we can remove this line?

I agree with @winterda, I changed it to

if (e.type === 'mousedown') {
    e.preventDefault();
}

to restore the vertical scroll behaviour on mobile devices but leave it as is on desktop devices.

where did you insert that code? @redboul

@jamesjsewell I guess in the tap method.

This but just a better approach.

I am using the change proposed by @redboul in production code without issues. I have created a PR #4702.

@redboul works like a charm! Thank you!

PR #4702 was merged so that @redboul 's solution is now in master and will be included in the next release.

I suppose this issue can be closed now.

This does restore vertical scrolling on mobile... but breaks horizontal carousel touch scrolling. It's arguably worse 馃槩

Tested with on 0.100.2, was previously on 0.98.2 with the original bug.

Should I open a new issue for touch scroll navigation being broken (which seems pretty major) or should we reopen this one?

Can you show us (in a codepen) that it is still broken? Then I would reopen this one :-)

I just tested all the versions between 0.98.2 and 0.100.2 ...it was indeed fixed in 0.99.0 (both vertical and horizontal touch scrolling were working). Then the larger break happened in 0.100.0.

I agree with @winterda, I changed it to

if (e.type === 'mousedown') {
    e.preventDefault();
}

to restore the vertical scroll behaviour on mobile devices but leave it as is on desktop devices.

Well done, that should do the work for you, it worked well for me.
just copy this above the carousel initial function to override the tap function.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

onigetoc picture onigetoc  路  3Comments

locomain picture locomain  路  3Comments

artur99 picture artur99  路  3Comments

bradley-varol picture bradley-varol  路  3Comments

heshamelmasry77 picture heshamelmasry77  路  3Comments