Hiding overflow-y through scrolling

I created a sleek little box that smoothly animates up from the bottom of the screen when a button is clicked, and gracefully slides back down when the same button is clicked again.

The design and functionality are spot on, but there's a slight issue. In order to prevent users from scrolling down and accidentally revealing the box, I implemented overflow-y: hidden on the body. However, this also hides other content on the page that I want users to be able to scroll through while keeping the box hidden and maintaining the animation effect.

Key CSS Elements:

body {
  padding: 0;
  margin: 0;
  position: relative;
  overflow-y: hidden;
}
.box-wrapper,
.box {
  position: absolute;
  bottom: 2em;
  left: 1em;
  z-index: 9;
}
.box-wrapper {
  transition-duration: 600ms;
  height: 100%;
}
.box-wrapper.hidden {
  transform: translate(0, 100%);
}

HTML Structure:

<div class="box-wrapper hidden">
  <div class="box">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa, quos?
  </div>
</div>

Included is a JavaScript snippet that removes the .hidden class upon clicking the button. For a live demonstration, check out the code in the fiddle.

Any suggestions for improving this setup? Thank you.

Answer №1

Instead of using position:absolute;, try utilizing position:fixed. Check out this example on http://jsfiddle.net/pcrv8ywy/2/

.box-wrapper,
.box {
position: fixed;
bottom: 2em;
left: 1em;
 z-index: 9;
}

.btn-circle {
background: #069;
color: #fff;
padding: 0.5em 0.8em;
border: none;
box-sizing: border-box;
border-radius: 50%;
font-size: 26px;
font-weight: bold;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
cursor: pointer;
position: fixed;
bottom: 1em;
left: 1em;
z-index: 10;
}

Answer №2

After some experimentation, I finally found the solution.
By adding an overlay that fills the whole screen and setting overflow-y: hidden, I was able to achieve the desired effect while still allowing the body to scroll.

If you're curious, you can view the result here.

UPDATE: Unfortunately, this approach is not ideal as it covers the entire body and hinders functionality. I'm still in need of assistance.

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

Submitting forms with Ajax without reloading the page can cause errors in Internet Explorer

Simply put: Upon clicking the login button in Firefox, Chrome, or Safari, the form is submitted correctly, running a validation via ajax and opening a new page. However, in Internet Explorer (version less than 9), the submission attempts to post to the c ...

When Hovering, Pseudo-class Cannot be Applied

In my design, I have an image overlaid with a Play icon. The concept is that when the user hovers over the image, the brightness of the image decreases and the Play icon is replaced with a Magnifying Glass icon. However, there seems to be a problem. When ...

What steps can I take to ensure my HTML5 mobile web app is optimized for compatibility across a variety of devices

I recently developed an HTML5 mobile web app and conducted tests on various devices including iPhones, iPads, Android phones, and tablets. What steps can I take to optimize the size and resolution of this app for seamless performance across all these dif ...

What is the best way to display a Facebook-like pop-up on a website

I am looking to implement a Facebook like box pop-up on my website for visitors. While I know how to show the pop-up, I am trying to determine how I can detect if someone has already liked my page in order to prevent the Facebook pop-up from appearing agai ...

jquery: displaying repeated divs on mouse hover - a tutorial

Let's say we have a div like this: <div class="y1"> <img src="i/o.png" /> </div> Also, we have this div for pre-loading: <!-- pre load --> <div class="p1" style="display:none"> <h5 class="ob">Title</h5> < ...

Creating diamond-shaped columns and rows in HTML using the Bootstrap framework is a fun and creative way to

Recently, I tackled the challenge of building a website based on a specific design. Within this design, there was a div element that included an image link. Despite my efforts, I found myself at a loss on how to proceed with this task. Here is the snippet ...

Make real-time edits to JavaScript code on a webpage

Is there a method aside from using Firebug in the DOM view to edit live JavaScript embedded within an HTML page? For example, code like this within a .html file: <script type="text/javascript> // code here </script> Thank you. ...

Contrasting JavaScript form submission with a form that includes a submit button

Could someone clarify the theoretical difference between using JavaScript to submit a form and having a form with a submit button? (I'm currently utilizing the Struts framework, but I believe that shouldn't impact the functionality.) For exampl ...

Unlocking the secrets of Nested JSON data in ngContainer

I am having trouble retrieving certain fields from a JSON Object in order to populate an expandable table using Angular Material. When I attempt to access these fields using the '.' or '[]' notation, the value returned is 'undefine ...

How to bypass validation for required input in jQuery validate plugin

As an example, consider the <input name="surname" id="surname" type="text">. Sometimes I want to hide this input and make it non-required. My current workaround is to set a value such as "some value" when hiding the input, and then remove this value ...

When the React.js app is launched on the server, it appears as a blank page, but functions perfectly when accessed locally

When I launch my React.js frontend locally with npm start, it runs smoothly. However, when attempting to run it on the server by using npm install followed by nom start, a blank page appears. Upon inspecting the public folder, I found the following conten ...

Widths for input fields (first name, middle name, and last name) inline in Twitter Bootstrap

I've been grappling with the sizing of inputs in Twitter-Bootstrap for a while now. I have a form that requires client address details. Specifically, I want to align the "Name" section (containing First name, middle name, and last name) in a single ro ...

Pop-up Registration Form Activation Using JQuery

I am attempting to create a Javascript jQuery registration form that appears in a pop-up window when a link is clicked. Here is the button I am working with: <a href="#" class="cta">REGISTER NOW</a> The goal is to have a simple HTML registra ...

"Render Failure" JavaScript and CSS files

I'm encountering a peculiar issue while attempting to load certain JS and CSS files. Within my ASP.NET MVC Web Project, I have an Index.html file where I've specified the loading of script files. It's worth noting that I have modified the U ...

Run a JavaScript function once the AJAX content has been successfully added to the element

I have a JavaScript AJAX function that retrieves content and adds it to an HTML element named content_holder. After the content is updated with the AJAX request, I want to trigger a function. I've attempted to include a <script> tag within the a ...

The alignment of Bootstrap 4 cards is not coming together as expected

Good morning, I'm currently working on organizing my Bootstrap card elements into rows of 3 cards each. I want the cards to be uniform in height and width, with spacing between them. For instance, if I have 7 cards, I'd have 3 rows of three card ...

Adding an arrow to a Material UI popover similar to a Tooltip

Can an Arrow be added to the Popover similar to the one in the ToolTip? https://i.stack.imgur.com/syWfg.png https://i.stack.imgur.com/4vBpC.png Is it possible to include an Arrow in the design of the Popover? ...

Avoid using the table and table-striped classes when working with Bootstrap 5 to ensure a

Recently updated to bootstrap5.0.0-beta3 along with bootstrap-table 1.18.2 from webjars repository. Here's the code snippet: <table id="table">...</table> <!-- no classes here --> $('#table').bootstrapTable({ ...

Sentence following the original passage

I want to achieve a similar look as the example below: Here is what I have done so far: h2:after { content: ""; display: inline-block; height: 0.5em; vertical-align: bottom; width: 48px; margin-right: -100%; margin-left: 10px; border-bo ...

Spinning Text with Dynamic jQuery Effects

I am looking to add a creative typography effect by rotating a portion of a sentence. I have experimented with jQuery animations. Specifically, I am interested in animating a word upwards. Here is the code snippet I have been working on: window.setInterv ...