Page elements subtly move when reloading in Chrome

I am experiencing an issue with a div that has left and top offsets randomly selected from an array of values upon page load. Most of the time, it works fine. However, occasionally, upon refreshing the page, the window scrolls down slightly, revealing the next section and causing all content to be shifted slightly to the left. Below are some screenshots showing this unexpected behavior. This is how the window appears after a refresh.

https://i.sstatic.net/KniPe.jpg

https://i.sstatic.net/cpEmK.jpg

Here's the code snippet:

<div class="about-section section">

    <div class="about-section__container">
        <h2 class="section-header about-section__header">About me.</h2>

        <p class="about-section__paragraph"></p>
    </div>
...
</div>
.section {
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

.about-section {
    background-image: url("../../../mountain-background.png.jpg");
    background-size: cover;
}

.about-section__container {
    position: absolute;
    display: block;
    visibility: hidden;
    left: 0;
    top: 0;
}

.about-section__header {
    color: white;
    font-size: 3.5em;
    font-family: 'Abril Fatface';
}
var title = $('.about-section__container');

var xIndex = Math.floor(Math.random() * 4);
var yIndex = Math.floor(Math.random() * 4);

var leftMargs = ['20%', '25%', '30%', '35%'];
var topMargs = ['25%', '30%', '35%', '40%'];

title.css({
    'left': leftMargs[xIndex],
    'top': topMargs[yIndex],
    'visibility': 'visible'
});

One key point to mention is that this problem occurs in Chrome but not Edge or Firefox. It seems as though the text container's offset affects the rest of the content - when the text moves to a new random position upon refresh, everything shifts to the left, causing the browser to scroll down if it moves downward. Additionally, this only happens upon refreshing, not during the initial visit.

Could this issue stem from my Javascript, styling of section containers, or background settings? Or could it be related to how Chrome caches CSS? I'm unsure what else to try, so any guidance would be greatly appreciated.

Answer №1

Make sure to include the following in your CSS file:

.section { 
    width: 100vw; 
    height: 100vh !important; 
    z-index: 1; 
    max-width: 100%; 
}

You can also try adding overflow-anchor: none; as it has been reported to work well too. A similar issue was discussed on this link Chrome Browser automatically scrolling

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

Using JavaScript ES6, we can access a specific array nested within a JSON array and loop through its elements by utilizing the

I have retrieved a JSON data from this link "response": [{ "id": "1", "title": "Star Wars", "project": [ "Star Wars Proj1", "Star Wars Proj2", "Star Wars Proj3", "Star Wars Proj4" ] }, { "id": "2", "titl ...

Having trouble with Gulp hanging on the task named 'some_task_name' when using gulp.parallel or gulp.series?

Out of the blue, my gulp configuration suddenly stopped working. It gets stuck on 'Starting...' when I use tasks with gulp.parallel or gulp.series. Just yesterday, the same config was running smoothly. Why did this sudden change occur? Here is a ...

Sort data by checking either multiple or single checkbox options in AngularJS; if none are selected, display all results

My goal is to implement a filter in my AngularJS code that will filter data based on selected checkboxes. If no checkbox is selected, all results should be displayed without any filtering. Currently, the issue I am facing is that the data is only displayed ...

The nightmare of Parent-Child Inheritance in JQuery/CSS is a constant struggle

Having difficulty implementing specific JQuery effects into a Bootstrap framework due to its extensive CSS causing issues. Created a test file named testjquery.html connected to a stylesheet defining a hidden element and activating the fade in of this ele ...

Linking promises to eliminate nesting

Hi everyone, I am currently working on chaining promises in my code. The initial HTTPS call returns an array of URLs successfully. After that, I loop through them to obtain a JSON object for each one. I am wondering if there is a way to reduce nesting in ...

Is the background element rather than its input being focused upon when clicking in the link tool's dialog within ContentTools?

I am utilizing ContentTools within a Bootstrap modal. The issue I am facing is that when I select text and click the hyperlink tool, the link dialog pops up but immediately focuses on an element in the background (such as the modal close button). This prev ...

Activating scrolling through Javascript

A friend of mine created a web page to help me learn some JavaScript. He designed a feature where the content in each div becomes visible as soon as the user scrolls past it. However, I noticed that the content appears too late for my liking. I would like ...

What is the best way to ensure that circles only touch each other by their edges?

Trying to align three circles touching each other has been a challenge for me. Although I have successfully managed to make two touch, the third one remains elusive. How can I ensure that all three circles are in contact with each other, especially when th ...

Event listener for clicking on a custom overlay in Google Maps

Incorporating Google Maps into an Ionic project, I have successfully added a custom overlay to display the address of a marker location on top of the map. By adding a click event listener to the map, I can detect clicks and update the marker for new locat ...

Ways to align content in the center using Vuetify3

I have a component positioned at the top of the page, but I would like it to be centered instead. https://i.sstatic.net/wSFBP.png Something like this: https://i.sstatic.net/rfqAB.png Here is my current code: <template> <v-container class=" ...

Accessing form data within Mongoose schema hooks via JavaScript

I have a form where I've split the content into two separate MongoDB schemas. I want to access variables that are within node.js/express.js directly in mongoose schema hooks, whether through pre or post hooks of the schema. Here are my files: expres ...

Incorporating Numerous Location Pointers in Angular-google-maps

I've been struggling to show multiple map markers in my Angular project. I have a service called retsAPI that queries a local MLS database for home listings, and I'm attempting to display these items on a Google map. Below is my controller code. ...

The mobile devices do not display minuscule text when rendering the React responsive UI

Recently, I decided to experiment with the responsive drawer feature of React Material UI. To try it out, you can access the online demo through the Code Sandbox link provided in the official documentation. To begin my testing, I copied and pasted the cod ...

Staggered Drop-Down Menus

I've created a custom CSS drop-down menu that works well, but I've realized that updating this menu across all the HTML pages on my website would be a tedious task. If I ever need to add a new section and tier to the menu, I'd have to update ...

Encountering a Typescript issue stating "Property 'then' does not exist" while attempting to chain promises using promise-middleware and thunk

Currently, I am utilizing redux-promise-middleware alongside redux-thunk to effectively chain my promises: import { Dispatch } from 'redux'; class Actions { private static _dispatcher: Dispatch<any>; public static get dispatcher() ...

Leverage the controller's properties and methods within the directive

My situation involves a variety of inputs, each with specific directives: <input mask-value="ssn" validate="checkSsn"/> <input mask-value="pin" validate="checkPin"/> These properties are managed in the controller: app.controller("Ctrl", [&ap ...

How to stop font-family and letter spacing from affecting the margin of div and ul elements in CSS

I'm facing a challenge with aligning a rotated div and an unordered list in a container. Adjusting the margin of either element does the trick, but changing font-family or letter-spacing globally affects the spacing between the two. Check out this JS ...

Tips for aligning a button in the center of an image across different screen sizes using CSS or bootstrap

I currently have a centered button on my hero image, but the issue is that I would need to use multiple media queries to ensure it stays centered on all screen sizes. <style> .hero-container{ position: relative; text-align: center; } .her ...

Unable to alter state from the onClick event of a dialog button

In the process of developing a Next.js app, I encountered an interesting challenge within one of the components involving a DropdownMenu that triggers a DialogAlert (both powered by Shadcn components). The issue arises when attempting to manage the dialog& ...

Having trouble retrieving data from the server for the POST request

I am fairly new to using Jquery and Ajax requests. I'm currently working on a website where I have a simple form that collects an email address from users and sends it to the server. However, I'm struggling to figure out how to capture the form d ...