-
Notifications
You must be signed in to change notification settings - Fork 149
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
Scroll behaviour not working on body when no explicit height is set #131
Comments
Welcome and thanks for providing a small example. I put up a stackblitz with your code and indeed - it's not scrolling 😞 You can play with it here https://stackblitz.com/edit/typescript-mobile-drag-drop-playground?file=style.css Related source code is mobile-drag-drop/src/scroll-behaviour.ts Lines 90 to 102 in 2b7ac0a
Maybe there is a better way to determine if an element is scrollable. Any hints and suggestions are greatly appreciated! |
Unfortunately I can't get your example to work either. Even with the overflow set, which would work for my current needs as a workaround, it is not scrolling on mobile (tested in Chrome on desktop simulated via dev tools and Chrome 66 on Android 7.1.1). |
So maybe |
The main issue is that the body element does not have a height restriction which causes it to not really be overflowing. It works when limiting the max-height of the body. https://stackblitz.com/edit/typescript-mobile-drag-drop-playground?file=style.css
Yes, there needs to be some special handling for the body to make it "just work". |
Oh boy, this special treatment of |
I hear you! The polyfill should enable it to just work so I flag this issue as a bug. The workaround of setting height to |
What about something like this in |
Maybe we can avoid any special workarounds on Basically the function findScrollableParent( el:HTMLElement ):HTMLElement {
do {
if( !el ) {
return null;
}
if( isScrollable( el ) ) {
return el;
}
} while( el = <HTMLElement>el.parentElement );
return null;
} function isScrollable( el:HTMLElement ):boolean {
if( el.scrollHeight > el.clientHeight ) {
if( el === document.documentElement ) {
return true;
}
const cs = getComputedStyle( el );
return cs.overflowY === "scroll" || cs.overflowY === "auto";
}
if( el.scrollWidth > el.clientWidth ) {
if( el === document.documentElement ) {
return true;
}
const cs = getComputedStyle( el );
return cs.overflowX === "scroll" || cs.overflowX === "auto";
}
return false;
} |
Looks like a neat solution. I'll give it a shot tomorrow and will report the result. |
I just gave it a test and it works kind of. Scrolling to the top works like a charm but to the bottom doesn't. It seems like it doesn't detect that the edge of the scrollable element is reached and therefore doesn't set scrollIntensions.vertical to 1. I'll do some deeper digging. |
So, the problem is in |
After some further investigation, my solution above works for scrolling to the buttom. But this also leads to another problem. Since the "ghost" element is being placed via translate3d, it adds up to the scrollHeight of the body when it gets close to the edge which leads to the issue that |
So finally after lots of testing and pulling my hair out on this, I got a solution for this which is working in my minimal example aswell as in the standard demo. Take a look at the last commit in my fork to see the changes. |
Thx for your effort 👍 Can you do a pull request containing your changes? |
Thank you for the help and the awesome polyfix! |
For some reason, I can't get the scroll behaviour to work. Even in an absolute minimalist setup like this:
HTML:
<div style="height: 500px;"></div>
<div style="padding: 50px; background: aqua;" draggable="true">drag me</div>
<div style="height: 1500px;"></div>
JS:
import {polyfill} from "mobile-drag-drop";
// optional import of scroll behaviour
import {scrollBehaviourDragImageTranslateOverride} from "mobile-drag-drop/scroll-behaviour";
polyfill( {
// use this to make use of the scroll behaviour
dragImageTranslateOverride: scrollBehaviourDragImageTranslateOverride
} );
window.addEventListener( "touchmove", function() {
// workaround to make scroll prevent work in iOS Safari > 10
} );
The dragging itself works fine though.
How can I get scrolling to work?
Thanks in advance!
The text was updated successfully, but these errors were encountered: