The vertical display size of the screen creates a quick flickering effect while scrolling on smartphones

While developing my website, I made extensive use of vh units. However, I noticed that in mobile browsers like Chrome, the browser's address bar disappears when scrolling down and re-appears when scrolling back up.

The problem is that this resizing causes all elements on my page to adjust due to the changes in document height caused by the address bar. Is there a workaround for this issue? Perhaps calculating the current device vh using jQuery initially and then converting all measurements to pixels instead of vh?

Any other suggestions or solutions would be greatly appreciated.

Thank you!

Answer №1

I recently encountered the same issue and found a solution that worked for me:

$(window).on('load', function() {
   var $vhElement = $("#vhElement");   //Select your element with 100vh
   var height = $vhElement.height();   //Retrieve rendered height in pixels
   $vhElement.css("height", height + "px");  //Override vh height with pixel height
});

If you have multiple elements requiring this adjustment, you can add a class to all of them and use the following code:

 $(window).on('load', function() {
   var $vhElements = $(".vhElement");   //Select all elements using vh
   $vhElements.each(function() {
       var height = $(this).height();   //Get rendered height in pixels
       $(this).css("height", height + "px");  //Override vh height with pixel height
   });
});

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

How to align the last item in the bottom row using Flexbox styling

Is it possible to center the last element when resizing the window to a smaller resolution, even though the parent's justify-content parameter is set to space-between? I understand that using center or space-around would achieve the desired result, bu ...

What is the best way to attach click handlers to a separate class?

I am facing an issue with two click events, "button-open" and "button-close". I have a button that switches from "button-open" to "button-close" on click. However, when I click it again, instead of firing the event for "button-close", it fires the event fo ...

Ways to avoid grid overflow

As a newcomer to CSS grid, I am struggling to understand how to prevent components from overflowing a grid. The section in question, with the class name of profile-widget-wrapper, is defined with grid-row:2/4 but is overflowing the grid. Can anyone provide ...

Incorporating an image within a table while maintaining 100% height: A step-by-step guide

I'm struggling to make the image fit 100% to the height of a CSS-created table. The table and image seem to be ignoring the dimensions of the parent element, as shown below. Since everything needs to be dynamic, I am working with percentages. .img ...

Highcharts: generating numerous series utilizing JSON dataset

I am struggling to generate a chart with multiple series using JSON data. Although I have successfully created one with a single series, it doesn't look right and the legend is missing. I need guidance on how to rectify this issue. Currently, I only h ...

Prevent all elements sharing the same class from expanding upon clicking if their parent element

Currently, I have implemented a function as a click event callback on a button. The purpose of this function is to toggle the class and provide a dropdown effect when the button is clicked. While this functionality works perfectly when the dropdown element ...

Tips for switching background images upon hovering over different elements

https://i.sstatic.net/GDjhE.jpgI have searched for similar questions but couldn't find a solution that fits my specific situation. Please bear in mind that I am new to this, so your patience and understanding are appreciated. Here is the code snippet ...

What is the best way to separate content into columns with a border in WordPress?

Currently, I am in the process of creating an event list for a music band website using WordPress. The layout of the list consists of two columns, and my goal is to alternate the placement of each event so that they appear in a left-right-left pattern. Ho ...

How can I make the default value change upon loading the page using jQuery?

I have set up an onchange method for a select box in my project. It is currently functioning as intended, showing and hiding a div based on the selected option. However, I am facing an issue where the show and hide functionality does not work for the def ...

"Enhancing iPhone User Experience with CSS Hover Effects

I am experiencing an issue with my website where the hover functionality works perfectly on all devices except for iPhones. On an iPhone, users have to continuously press the screen until the hover transition completes in order to view the information. I ...

Activate Bootstrap modal using an anchor tag that links to a valid external URL as a fallback option

To ensure accessibility for users who may have javascript disabled, we follow a company standard of developing our web pages accordingly. Our target demographic still includes those familiar with VCRs blinking 12:00. One particular challenge involves a te ...

Initiate an animation as you scroll down

How can I create an animation that transitions from color to grayscale, triggered only when the user scrolls down? This is necessary because my website contains numerous images that require scrolling to reach. Check out the fiddle example here: http://jsf ...

Submitting a Form with Ajax and JQuery in .NET

Thanks to the help of balexandre and rtiq, I have successfully figured out the flow. My .ashx file is being called, indicating that a portion of the code is functioning correctly, although an error is being alerted. However, when I trace the .NET, the vari ...

"Incorporate a search bar into the drop-down menu for easier

I'm struggling with creating a select dropdown that includes a search box inside. How can I properly position the search box within the dropdown? I've tried using position relative and absolute, but even when specifying top: 10px, the element doe ...

When viewing a page in IE 9 within a frame, not all CSS styles are properly rendered, causing it to enter Quirks mode

When a web page is loaded within a frame, not all of its styles are applied. The specific stylesheet used for the div elements is as follows: div.super{ position:absolute; font-family: Helvetica; font-size: 0.75em; padding:4px; overflo ...

Modify the original source data of an HTML table

I have written the following code: <table class="table table-hover"> <thead> <tr> <th>Status</th> <th>MPK</th> <th>Full Name</th> <th>Phone Number</th> <th>Proj ...

Issue with Bootstrap 5 and vertical ruler (vr) not displaying current color

Utilizing the vr feature from Bootstrap 5 to establish vertical ruler divisions in col-sm-1 between three chartjs graphs in col-sm-3. Encountering a peculiar issue where one vr appears slightly darker than the other. Struggling to determine the cause of th ...

Why does the jQuery "alert" function work, but the image "src" setting is being overlooked?

Building on the previous inquiry: Can't I use JQuery inside my FancyZoom popup? The solutions provided in response to that query resolved the issue of consistently triggering our Hello World alert within our FancyZoom popup. However, our ultimate g ...

What steps can I take to resolve the issue of Images and CSS not loading properly in my project?

My process for setting up the JavaScript development environment was straightforward. I followed the steps outlined in this helpful resource: JavaScript Development Environment Setup Below is a snippet of my HTML code: <html> <head> ...

What is the best situation to utilize $(document).ready()?

After observing that using $(document).ready(..) seems to introduce a noticeable delay in applying JavaScript effects, I've been contemplating the best approach. I know that simply placing the effect in a <script> tag may not work if the DOM isn ...