Solved the issue of inconsistent element height and jumping on mobile devices during scrolling

Problem persists with the fixed element at the bottom of my mobile device when I scroll. It seems that the height is recalculated each time due to an increase in document height on mobile devices.

The issue appears to be related to the address bar fading out, causing the document viewport to enlarge. Despite trying various solutions like setting height: 100% for both html and body, no success has been achieved.

A demonstration GIF illustrates scrolling on the page through a phone's chrome browser, highlighting the transparency of the address bar:

https://i.sstatic.net/Zthsg.gif

This is the code currently implemented:

#wrapper {
  position: fixed;
  background: darkcyan;
  color: #fff;
  bottom: 0;
  left: 0;
  right: 0;
  top: calc(100% - 100px);
  width: 100%;
}

#bottom-element {
  height: 50px;
  position: fixed;
  background: black;
  display: block;
  bottom: 0;
  width: 100%;
  left: 0;
  right: 0;
}

#title {
  text-align: center;
  padding: 15px;
  height: 20px;
  border-bottom: 1px solid white;
}

#entries {
  display: flex;
  flex-direction: column;
      overflow: scroll;
    overflow-x: hidden;
}

.entry {
  padding: 15px;
  background: cadetblue;
}
<div id="wrapper">
  <div id="title"></div>
  <div id="entries">
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
  </div>
</div>
<div id="bottom-element"></div>

An expanding div is intended to reach up to 80% of the screen from the bottom. Is there a fix to this problem? I adjust the top value dynamically to expand my element, so maintaining the layout is crucial in any proposed solution.

Answer №1

The problem lies in the top value being calculated. I've made changes to the code from your previous question's answer, approaching it differently (finding alternative ways to achieve the same outcome).

In this revised example, height animation is used instead of adjusting the top value. The bottom property is set on the wrapper so it remains anchored regardless of the page's height fluctuations. Adjust the height as necessary.

const title = document.getElementById("title");
const wrapper = document.getElementById("wrapper");

title.addEventListener("click", () => {
   wrapper.classList.toggle("expanded"); 
});
#wrapper {
  position: fixed;
  background: gray;
  color: #fff;
  bottom: 42px;
  left: 0;
  right: 0;
  border-radius: 12px 12px 0 0;
  width: 100%;
  transition: height 250ms ease-in-out;
  height: 42px;
}

#wrapper.expanded {
    height: 85vh;
}

#title {
  text-align: center;
  padding: 15px;
  border-bottom: 1px solid white;
}

#notifications {
  display: flex;
  flex-direction: column;
      overflow: scroll;
    overflow-x: hidden;
}

.entry {
  padding: 15px;
}
<div id="wrapper">
  <div id="title">Notifications</div>
  <div id="notifications">
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
    <div class="entry">Test</div>
  </div>
</div>

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

Creating a triangle shape using Bootstrap to style a div element, similar to the image provided

Trying to achieve the look of the attached image with a few divs. I know I can use a background image like this: background:url(image.png) no-repeat left top; But I'm curious if there's another way to achieve this without using a background ima ...

Deleting an HTML column that has a dynamic header name <th> can be achieved by following these steps

I have a script that can add a new column to an HTML table. When the user clicks on add group, the header will change to Group1, Group2, and so on. I am currently adding a function for delete group that can delete all the added columns. The issue now is th ...

Implement a unique InfoWindow for every individual polygon within the Google Maps API

Currently facing difficulties in implementing an infowindow for each polygon that has been created. Attempted various code samples from different sources without success. Below is the existing code snippet, but clicking on a polygon does not trigger any ac ...

Issue when activating Materialize Bootstrap

I'm facing an issue with my code. I have implemented a feature where a modal should be triggered after a user successfully adds a new user. However, I am using Materialize and the modal is not being triggered. Below is a snippet of my code: <div i ...

Hold off on showing the image until it has finished loading

// Here's the code snippet angular .module('imgapp', []) .controller('mainCtrl', mainCtrl); function mainCtrl() { var vm = this; vm.first = { title: 'Image 1', url: 'http://www.image-mapper.com ...

Unique style pattern for parent links with both nested and non-nested elements

I am in the process of designing a website and I have a specific vision for how I want my links to appear, but I am unsure of how to achieve it. Here is the desired outcome: a red link a green link a red link a green link … Below is the HTM ...

How can one ensure that the column width in a Datatable adjusts dynamically based on the content within?

My data table creation code looks like this: var Master = $('#MasterGrid').DataTable( { "data": response, "columns":columns, "scrollX": true, }); $('#Mas ...

I need the PHP code to ensure that only checkboxes can

I keep encountering what seems like a simple issue in my html form with checkbox groups. I am trying to ensure that at least one checkbox is selected from each group, and if not, display an error message using PHP code. However, despite multiple attempts, ...

The overlay background on the image does not seem to be functioning correctly

I'm currently working on adding an overlay to my image in order to darken it and display text over the top. I've tried using absolute positioning for both the image and overlay, but the overlay ends up covering the entire window and sitting above ...

Eliminate any HTML content using Jsoup while retaining the text lines

I am working with a String that contains e-mail content, and my goal is to eliminate all HTML coding from this String. This is the current code I have: public static String html2text(String html) { Document document = Jsoup.parse(html); document = ...

What methods can I use to ensure my HTML/CSS code is compatible with all browsers? It functions properly on Chrome but encounters issues on Safari, Edge, and other

My hosting for the website is with bluehost, and interestingly when viewed on Chrome, everything appears perfect. However, upon switching to Safari, I noticed that the background of the about me section is not black as intended, and the footer seems to be ...

Creating a div that spans the entire height from top to bottom

Currently, I am faced with the following scenario: <div id=area> <div id=box> </div> </div> <div id=footer> </div> The "area" div is situated in the center and has a width of 700px with shadows on both the right and ...

Tips on keeping the size of a react-bootstrap modal constant and enabling scrolling instead of expanding

<Modal size="lg" scrollable show={showInvModal} onHide={handleCloseInvModal}> <Modal.Header closeButton> <Modal.Title>Check out our latest items!</Modal.Title> </Modal ...

Transformation of a double-row header

Click here to view the design - two-row header image I'm struggling with creating a header design that consists of two rows - the first row includes a centered logo and icons on the right side, while the second row contains the menu. Can someone guid ...

What seems to be the issue with my 2-column design layout?

When I try to arrange my webpage with a 2 column layout, adding an image messes up the footer. Without the image, the footer looks correct. <!DOCTYPE html> <html lang="en"> <head> <title>SuperRestraunt</title> ...

Prevent the Stop Button from triggering submission and then utilize JavaScript to submit the form

I have a global delete button utilized in various sections of my site. Below is the code snippet for reference. public function delete_button($id_to_be_deleted, $form_to_post_to, $button_name){ return form_open($form_to_post_to, array('class&apos ...

Page flickers when jQuery is used to scroll to an element

One issue I have encountered is with a link that, when clicked, should scroll down to a specific element on the page. However, every time I test this feature, there seems to be an inconsistency where the page may momentarily flash before scrolling as inte ...

The implementation of a secondary sidebar for internal pages

Currently, I am in the process of customizing a Wordpress theme and my goal is to achieve a similar 3-column layout for the homepage as seen on . Specifically, I am interested in replicating the inner sidebar's custom image title. The theme I'm ...

Is there a way to apply the 'absolute' or 'fixed' with a width of 100% to the parent div specifically, rather than to the window size?

I would like to create a banner similar to the one shown here: https://i.sstatic.net/SZLr9.png I am attempting to achieve this using 'absolute' or 'fixed' positioning. However, when I tried using 'left: 0 right: 0 top: 0', i ...

What might prevent an onSubmit event from triggering the execution of "checkTheForm()"?

Despite consuming a substantial amount of information on the internet, I still find myself puzzled by why my code isn't functioning as expected. I acknowledge that there are numerous tutorials out there guiding me to use <form action="index.html" o ...