question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable Scrolling scrolls to top when image is clicked.

See original GitHub issue

Why does clicking the image to open the modal scrolls the page to the top when disableScrolling is true?

To produce the following bug, go to Lightbox Examples, open the console, and enter the following.

lightbox.option({ disableScrolling: true });

Then before clicking an image, scroll so that you’re not at the top of the page but you should still see the image (so you could click it tho).

After clicking, you can see that the modal opens but the page scrolls up, leaving the modal down there! Are there other things that I should do when implementing disableScrolling?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jrpeters89commented, Mar 28, 2018

It looks like the class “.lb-disable-scrolling” is the issue. I commented out the “position: fixed;” attribute and it seems to be working fine now on desktop.

html.lb-disable-scrolling {
  overflow: hidden;
  /* Position fixed required for iOS. Just putting overflow: hidden; on the body is not enough. */
  //position: fixed;
  height: 100vh;
  width: 100vw;
}

The author put a note in here though saying position: fixed is required for iOS. I am going to add this to the css to see if I can make it work on iOS as well (haven’t tested yet):

@supports (-webkit-overflow-scrolling: touch) {
  /* CSS specific to iOS devices */
  html.lb-disable-scrolling {
    /* Position fixed required for iOS. Just putting overflow: hidden; on the body is not enough. */
    position: fixed;
  }
}
0reactions
ashok-2695commented, Nov 24, 2021

Just Add below line to your lightbox-plus-jquery.min.js file .

lightbox.option({ disableScrolling: true });

Capture4

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I stop a web page from scrolling to the top when a link ...
This way when the link is clicked the page won't scroll to top. This is cleaner than using href="#" and then preventing the...
Read more >
How to disable scrolling temporarily using JavaScript
The current scroll position from the top is found by using the window.pageYOffset and the document.documentElement.scrollTop values.
Read more >
How To Create a Scroll Back To Top Button - W3Schools
This example demonstrates how to create a "scroll to top" button that becomes visible when the user starts to scroll the page. Try...
Read more >
overscroll-behavior - CSS: Cascading Style Sheets | MDN
The overscroll-behavior CSS property sets what a browser does when reaching the boundary of a scrolling area.
Read more >
Prevent Page Scrolling When a Modal is Open | CSS-Tricks
If we know the top of the scroll location and add it to our CSS, then the body will not scroll back to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found