Use Case : - If the user is scrolling an inner div it should not scroll the outer div once inner div end has reached.
The following code works perfectly fine if the inner div has already reached the end. i.e the touchstart/touchmove event triggers after the inner div has reached the end.
But in case I do not lift the touch and keeps scrolling and if the end of the inner div has reached in this process, it starts scrolling the outer div.
$('body').find('.scrollableDiv').on(
{
'touchstart' : function(e) {
touchStartEvent = e;
},
'touchmove' : function(e) {
e.stopImmediatePropagation();
$this = $(this);
if ((e.originalEvent.touches[0].pageY > touchStartEvent.originalEvent.touches[0].pageY && this.scrollTop == 0) ||
(e.originalEvent.touches[0].pageY < touchStartEvent.originalEvent.touches[0].pageY && this.scrollTop + this.offsetHeight >= this.scrollHeight)){
e.preventDefault();
}
},
});
How do I stop scrolling as soon as the end of the inner div is reached? I am trying to achieve this on a browser on android device. Can someone help me in this regard?
NOTE : The user should even be able to scroll the outer div.
Thanks in advance.
And it is simply by adding the CSS property overflow: hidden; on the element you want to prevent the scroll.
To prevent scrolling with this property, just apply the rule overflow: hidden to the body (for the entire page) or a container element. This hides all content beyond the element's border.
use css position top keep it at the bottom {position : relative; bottom:0;} . Remove the css property once the user has scroll.
I'm afraid I don't have time to write the explicit code to solve this, but I've got a conceptual solution for you that still might help you.
position: relative
.overflow: scroll
, set overflow: visible
, position: absolute
, get calculated height & width and apply these as inline styles, and set top to be the negative of scrollTop — and set the wrapper's overflow
to hidden
: this means it will be in the same position it was in the first place but unable to move through scrolling.I can already see caveats:
…but it's definitely feasible…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With