Is it possible to make the `<body>` element respect the offset (i.e. the user's current scroll position) when the 'custombox' modal is triggered?

I'm currently facing an issue with the scroll bars in the browser while using custombox.js in combination with BS4.

Let me provide some context:

I am working with a Custombox modal, which is similar to a BS4 modal. When a modal is opened in BS4, a class is added to the body tag called .modal-open, which prevents scrolling by hiding the scrollbar.

This behavior of hiding the browser's scroll feature while the modal is open sometimes results in jitters, which is not desirable.

To address this issue, I came up with the following solution:

/* Custom Box Lock */
.custombox-lock {
  position: fixed;
  left: inherit;
  overflow-y:scroll !important;
}

This new class ensures that the scrollbar remains visible while locking the user in place to disable scrolling.

The Dilemma

However, applying this class causes the user to jump to the top of the page when the modal opens, which is far from ideal.

I tried using inherit: left; to maintain the scroll position, but unfortunately, it did not work as intended.

Question: Is there a simpler way to achieve the desired result without complicating things further?

Answer №1

Instead of worrying about

.modal-open { overflow: hidden; }
causing issues, simply override it with
.modal-open { overflow: scroll !important; }
. Remember that Bootstrap classes can easily be modified in this way.

However, I have a different theory about what might be causing your problem. The issue may not stem from that particular line of code. This line simply conceals the overflow within the modal itself. To consistently display the page's scrollbar, consider adding

body{overflow: scroll !important}

to your project. By implementing this change, the scrollbar will always be visible without any disruptions when you open a modal window.

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

Combine the text value from a textbox and the value from a checkbox into a single

I'm trying to solve a challenge regarding appending values from text fields (excluding empty ones) and checkboxes in a specific order to form a string. It should be in the format: name|T|F_name|F|F. Once I've created this string, I plan to send i ...

Creating visually appealing table designs with CSS

Greetings! I am currently utilizing JQuery fullCalendar within AngularJS and find myself in need of assistance regarding table styling. The fullcalendar has its own CSS file from the plugin, which can be viewed here. The issue arises due to the presence o ...

Utilize images inputted via an HTML DOM file uploader within p5.js

I'm facing a challenge with allowing users to upload their image file through a DOM file uploader (<input type="file"></input>). Once the image is uploaded, I'm unsure of how to transfer it to JavaScript and process it using p5.js. Ho ...

Develop an outline using D3.js for the clipath shape

After successfully creating a shape with a color gradient, I encountered the need for further customization. If you are interested in this topic, check out these related questions: Add multi color gradient for different points in d3.js d3.js scatter plot c ...

The inclusion of Jquery Mobile causes CSS to malfunction

After integrating jQuery Mobile into my HTML via a CDN, I noticed that it completely overrides my styles and disrupts my design. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" /> <script src="http:// ...

Saving data values for utilization in jQuery

Recently, I've come across a series of links structured like this: <a class="colorBox" href="#" title="#0676B3"></a> <a ... <a ... these links all have color values in the title attribute <a ... What I'm trying to do is uti ...

Using Button Click in ASP to Remove a Row from SQL Server: Exploring Classic ASP and VBScript

I have successfully designed a webpage using asp that showcases a table fetched from an SQL database. To enhance the functionality, I incorporated buttons for updating and deleting each individual row within the code snippet below: do while not objRS. ...

Having trouble invoking an ASMX web service using jQuery's Ajax functionality

Currently, I am running an asmx service on port localhost:5739 and attempting to call the service from another port or plain HTML + jQuery outside of the project. However, I am encountering difficulties in accessing the web service. The structure of my w ...

PHP form does not seem to be vulnerable to cross-site scripting attacks

On one of my web pages, I have a form with an action php page using the following html syntax: <form name="form" action="test.php" method="get"> I decided to make it more secure by modifying it to: <form name="form" action="<?php echo htmlsp ...

Datatables efficiently retrieve search data directly from the client side while processing on the server side

I've been tackling this issue daily without any luck in finding a solution. My problem can be described as follows: When searching for the date 25th Apr, it doesn't work; however, if you search using the format 04-25, it works. In my current pr ...

What is the process for executing JavaScript and triggering a postback?

How can I create an 'Add to Favorites' button that changes the image in JavaScript and then performs a postback on an ASP.NET page? aspx <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-t ...

Automatically updating database with Ajax post submission

I have customized the code found at this link (http://www.w3schools.com/PHP/php_ajax_database.asp) to update and display my database when an input box is filled out and a button is clicked to submit. Below is the modified code: <form method="post" acti ...

Create a right-to-left (RTL) CSS file within a create-react-app project and dynamically switch between them depending on changes

I am currently working on a multi-language project using create-react-app. My goal is to incorporate a library like "cssJanus" or "rtlcss" to transform the Sass generated CSS file into a separate file. This way, I can utilize the newly created file when sw ...

Changing the Color of Hamburger Menu Lines in Bootstrap

How can I change the color of the hamburger menu icon's lines for medium and smaller screen sizes? I have attempted changing it through style attributes and using !important in my CSS file, but so far nothing has been successful. ...

How can you receive a file through AJAX response?

I have a standard Ajax function that I regularly use to call a specific function within my node.js server. This particular function is responsible for retrieving a file (usually in xls format) from the server and streaming it back to the client. Below is ...

The error message of "Node v0.10.37 is not compatible with Autoprefixer"

When attempting to access localhost:3000, an error is thrown stating: ActionView::Template::Error (Autoprefixer doesn’t support Node v0.10.37. Update it.): I have tried updating node, but there are no updates available. node -v # v8.1.3 nodejs -v # v0 ...

"Fetching a textbox value and passing it into an anchor tag query string: a step-by-step

What is the best way to extract a value from an "asp:TextBox" and insert it into an anchor tag? The asp:TextBox I am working with is labeled txtTaskName. <a href='EmailManager.aspx?<%# Eval(txtTaskName.Text) %>' runat="server">Add E ...

Setting the value for a HiddenField using jQuery in an ASP.NET application

Is there a way to set a value for a HiddenField control using jQuery? function DisplayContent(obj) { var FareValue = $(obj).closest('tr').find("[id*=lbFare]").text(); $(obj).parent().parent().find('[id*=pnlGrd]').show(); $ ...

What can be done to stop a header from sticking to a table and displaying horizontally scrolling content along the border?

I need to ensure that the red headers do not overlap with the blue headers' borders while scrolling horizontally. It is essential for me to have a white border on the blue headers. .container { overflow: auto; width: 200px; } table { borde ...

Having additional space preceding list elements within a flexbox setup

Check out the code snippet below: HTML Code <ul class="menu"> <li><a href="#">Item 1</a></li> <li> <a href="#">Item 2</a> </li> <li> <a href="#">Item 3</a> </li& ...