Prevent body scrolling on Mobile Safari by using JavaScript

My goal is to prevent the body of my page from scrolling altogether when a modal overlay is open.

The modal occupies the entire screen (

{position: fixed;top:0;left:0;right:0;bottom:0;}
) and has its own scroll functionality. However, upon reaching the end of the modal window's scroll, the main window starts scrolling behind it. Despite trying various methods to stop the body from scrolling, none have been successful:

CSS

body {
    overflow: hidden;
    pointer-events: none;
    -webkit-overflow-scrolling: none;
}
#content { /* which contains all the non-modal content of the body */
    -webkit-transform: scale(0);
    position: relative; left: 100%;
}
  • Attempts with iScroll
  • Preventing the scroll event on the window or body
  • Blocking the touchstart event on the body

Answer №1

Seems like you're almost there.

If your modal is currently displayed, experiment with this CSS:

body{
    overflow:visible;
    max-height:100%; /* adjust as needed */
    height:100% /* adjust as needed */
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The aspect ratio of a DIV element is not maintaining its scale properly in Firefox

My current challenge involves using a Script to Scale a Div while maintaining the aspect ratio. The objective is to ensure that 100% of the DIV remains visible while maximizing its size. As you scale the browser width, the div adjusts its height to 100%, a ...

transferring data from one HTML file to another using a loop with technologies such as HTML,

As a beginner in front end development, I am finding it a bit challenging at the moment. Here's what I have so far: 1 main HTML file (index.html) 1 JavaScript file (something.js) 2nd HTML file (something.html) Main HTML: <!DOCTYPE html> < ...

Bootstrap 4's column ordering feature is malfunctioning

<div class="container"> <div class="row"> <div class="col-lg-8 col-md-12 order-2">1 </div> <div class="col-lg-4 col-md-12 order-1">2 </div> </div> </div> I need to change the orderi ...

Mysterious extra space appearing on the right side of the left scroll div in Chrome

I am currently working with a table that dynamically increases in content when a button is clicked. I have successfully implemented a scroll on the right side to handle overflow. However, I encountered an issue when trying to change the scroll to the left ...

I am struggling to get the images aligned properly on my HTML page. Can someone please advise on how to fix this issue?

On my HTML page, I have 2 div fields. Within each field, there are 5 images listed sideways. The issue is that the images in the div below are not lining up properly side by side. Given my limited frontend knowledge, how can I align them correctly? Here&a ...

The dropdown div does not activate when the image is clicked

When the image in the simple dropdown is clicked, it fails to activate the dropdown feature. This issue was encountered while working on a Shopify project, making it challenging to troubleshoot. To demonstrate the problem, I have re-created the scenario i ...

The fuse-sidebar elements are not being properly highlighted by Introjs

I have recently developed an angular project that utilizes the fuse-sidebar component. Additionally, I am incorporating introjs into the project. While introjs is functioning properly, it does not highlight elements contained within the fuse-sidebar. The ...

How can CSS animations be implemented on a diagonal path?

I have developed a unique CSS animation that adds a shiny effect to text. Currently, the effect only works horizontally. I am interested in exploring options to change the direction of the animation to create a diagonal shine effect. Below is the code I a ...

Imitate the actions of images with {width: 100%; height : auto} properties

I am interested in creating a unique layout that consists of a stripe composed of images with varying widths and heights. These images need to be proportional, scaled at the same height, and collectively have a width equal to the parent element. However, ...

What could be the reason the background-color isn't changing when I apply button:hover?

body{ font-family:"Arial","Lucida Grande", "Lucida Sans Unicode", Verdana, Helvetica, sans-serif; font-size:12px; } p, h1, form, button{border:0; margin:0; padding:0;} .spacer{clear:both; height:1px;} /* ----------- My Form ----------- */ .myform{ margin:0 ...

Detecting the preferential usage of -webkit-calc instead of calc through JavaScript feature detection

While it's commonly advised to use feature detection over browser detection in JavaScript, sometimes specific scenarios call for the latter. An example of this can be seen with jQuery 1.9's removal of $.browser. Despite the general recommendatio ...

The outputstring encountered an issue with the HTML class

Struggling a bit with php, I'm trying to incorporate a basic comment system that accesses and writes to a comments.php file. Everything is functioning well until I attempt to style the $outputstring. Here's the code in question: $outputstring ...

Make the navigation arrow bigger in bootstrap 4

I need help creating a carousel with two navigation arrows in Bootstrap 4. Below is the code for the carousel controls: <!-- Carousel controls --> <a class="carousel-control left carousel-control-prev" href="#myCarousel" ...

How to prevent table row from highlighting on hover in Angular Bootstrap

In my project, I have a table that showcases various details and allows users to select certain rows. Some of these rows have child rows which can also be selected. The requirement is for the parent rows to be selectable only if they do not have any child ...

Troubleshooting issues when utilizing flexbox in Firefox and Chrome version 48

Chrome 47 Behavior: The .scroll div scrolls correctly in Chrome 47, taking up 100% height using flex. Firefox Behavior: In Firefox, the .scroll div does not scroll properly and instead uses the content height. What is the solution that works across diffe ...

Embellishing Bootstrap with a splash of color class

After exploring Bootstrap, I've noticed the limited number of "color classes" available (primary, success, danger etc.). Is there a simple way to add more classes similar to those? For instance, the "primary" class can be used across various elements ...

"Click to view the latest data visualization using the Chart.js

I am exploring ways to enhance the animations in Chart.js for a new web project. The content is organized in tabs, with the chart displayed on the third tab out of four. Currently, the chart animates upon loading. How can I make it so that when #chartTrig ...

IE10 is not effectively handling multiple media queries

Within my CSS file, I've included a series of media queries specifically tailored for ie10... @media screen and (max-width :1510px), screen\0{ div.jw-menu-3col-sm li a .menuItem { padding: 0 12px; } } @media screen ...

A guide to implementing drag and drop functionality using JavaScript

I have developed a unique drag and drop application that features both a left and right panel. The issue I am facing is that when I drag the ball from the left panel to the right panel, it does get dragged successfully. However, the problem arises when the ...

Understanding how to automatically adjust margins in Bootstrap based on screen width

When viewing in fullscreen, the margins are set to ensure the container fits entirely within the page. However, without the 200px margin in the .gallery class, the container would be too big to fit on the page without scrolling. The problem arises when th ...