body-scroll-lock icon indicating copy to clipboard operation
body-scroll-lock copied to clipboard

Content in the target not scrolling

Open paragonn opened this issue 5 years ago • 19 comments

I implemented the script on a plain vanilla js config and it is successfully locking the body scroll, however the content in the target is not scrolling. Their are 4 pages (slides) inside the target as part of a stepped form. The second step in the form is larger than the mobile screen size however it is not scrolling. You can see a demo here: https://dev.ijm.org and click on the red Give button. Help would be greatly appreciated!

paragonn avatar Apr 04 '19 19:04 paragonn

Can you try using the allowTouchMove option?

diachedelic avatar Apr 04 '19 22:04 diachedelic

Thanks @diachedelic -- I applied the allowTouchMove to the #draw1-wrap div and the scroll now works, however the body unfortunately scrolls too?

paragonn avatar Apr 04 '19 22:04 paragonn

Can you paste your allowTouchMove function here?

diachedelic avatar Apr 04 '19 23:04 diachedelic

Sure thing @diachedelic, here it is:

disableBodyScroll(targetElement, {
  allowTouchMove: el => (document.querySelector("#draw1-wrap"))
});  

paragonn avatar Apr 04 '19 23:04 paragonn

allowTouchMove expects a boolean, try this:

disableBodyScroll(targetElement, {
  allowTouchMove: el => (el === document.querySelector("#draw1-wrap"))
}); 

diachedelic avatar Apr 04 '19 23:04 diachedelic

Thanks @diachedelic -- The body scroll lock is now working again, however the content on page/slide 2 is not vertical scrolling. Do you think it could have something to do with a styling in the css?

paragonn avatar Apr 04 '19 23:04 paragonn

Same problem here.

retailonline avatar Apr 05 '19 00:04 retailonline

@paragonn #draw1-wrap is possibly not the correct element to target, or you need to target other elements too - make sure you target all elements which have overflowing content.

diachedelic avatar Apr 05 '19 01:04 diachedelic

image

Looking at your demo, try targeting div.drawer instead

diachedelic avatar Apr 05 '19 01:04 diachedelic

Thanks for your assistance @diachedelic -- I tried your recommendation and overflow content still does not vertical scroll. Here is the code for the current staging (dev.ijm.org) of the problem:

disableBodyScroll(targetElement, {
  allowTouchMove: el => (el === document.querySelector("#draw1-wrap"))
});   

Where the targetElement is defined like so:

const targetElement = document.querySelector("#draw1");

Do you have any other recommendations?

paragonn avatar Apr 05 '19 04:04 paragonn

I see you've used the body-scroll-lock-ignore attribute - for that attribute to work, you need to adjust your allowTouchMove function like

  disableBodyScroll(container, {
    allowTouchMove: el => {
      while (el && el !== document.body) {
        if (el.getAttribute('body-scroll-lock-ignore') !== null) {
          return true
        }
  
        el = el.parentNode
      }
    },
  });

And you can safely remove body-scroll-lock-ignore from all the children elements - you only need it on the outermost scrolling element, all elements within will automatically be allowed to scroll.

diachedelic avatar Apr 05 '19 05:04 diachedelic

So just leave it on #draw1-wrap like <div id="draw1-wrap" body-scroll-lock-ignore> (doing body-scroll-lock-ignore="" might do the opposite of what you want...)

diachedelic avatar Apr 05 '19 05:04 diachedelic

If there is a parent between body and target's parent, and that parent has overflowing content, is it going to work? Or the scroll lock should be applied on the component inside that between parent?

limaneto avatar Jul 15 '19 19:07 limaneto

@limaneto I'm having a hard time visualising your issue, could you post a JS Fiddle or something?

diachedelic avatar Jul 15 '19 23:07 diachedelic

do you guys have any live example with React?

limaneto avatar Jul 16 '19 00:07 limaneto

I have no idea, I'll wait for someone else to answer that

On 16 Jul 2019, at 10:34 am, Lima Neto [email protected] wrote:

do you guys have any live example with React?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/willmcpo/body-scroll-lock/issues/100?email_source=notifications&email_token=AACLZQHQOZY3P47L24MFPATP7UJSVA5CNFSM4HDV7MXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ7K5TQ#issuecomment-511618766, or mute the thread https://github.com/notifications/unsubscribe-auth/AACLZQEWWGBDWNSPEPA2WK3P7UJSVANCNFSM4HDV7MXA.

diachedelic avatar Jul 16 '19 00:07 diachedelic

For the people that still have this problem after trying the fix... Try destroying the body and turning the div into the body dynamically. And add a close button that reloads the page. Hacky, but works perfectly in my project.

bobberg avatar Jul 16 '19 12:07 bobberg

Used this package in React, added the attribute to the component as a prop.

The rest of the code was as suggested by the Documentation.

To get this working, we grabbed the component through a class and <className>.setAttribute('body-scroll-lock-ignore', 'true') within componentDidUpdate()

Keep in mind you could do the same with ID, jsut replace the code above with ID instead of Class stuff, etc

Might help out some of you :smiley:

llausa avatar Aug 27 '20 01:08 llausa

@llausa mind creating a small snippet/code sandbox for react?

I'm struggling with the same problem, for now, I avoided using the scroll lock in just one view where I have a drawer where I need the scroll

abeledovictor avatar Oct 27 '20 03:10 abeledovictor