Animating elements within Firefox can sometimes cause adjacent elements to shift positions

Currently, I am working on a single-page website that utilizes keyboard-controlled scrolling.

To achieve the desired scroll effect, I have developed a JavaScript function that animates divs.

Here is the JavaScript code:

var current_page = "#first";
function animateScroll(curr, des){
    $(des).show();
    $(des).css("position", "absolute");
    $(des).css("z-index", "2");
    $(curr).css("z-index", "1");
    $(des).css("top", "100%");
    $(des).animate({
        top : "0px"
    }, 800, function(){
        $(curr).hide();
        current_page = des;
    });
}
$(document).on("keyup", function(e){
    if(e.keyCode === 40){
        animateScroll(current_page, "#" + $(current_page).next().attr("id"));
    }
});

Below is the HTML structure:

<div id='why_am_i_moving'></div>
<div class='main' id='first'>press down key</div>
<div class='main' id='second'></div>
<div class='main' id='third'></div>
<div class='main' id='fourth'></div>
<div class='main' id='fifth'></div>

And here is the CSS styling:

body, html{
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
div.main{
    width: 100%;
    height: 100%;
    display: none;
    background: white;
}
#first{
    background: red;
    display: block;
}
#second{
    background: blue;
}
#third{
    background: green;
}
#fourth{
    background: yellow;
}
#why_am_i_moving{
    position: absolute;
    bottom: 0;
    width: 200px;
    height: 200px;
    background: brown;
    z-index: 3;
}

However, I encountered an issue where all elements on the page move slightly upward before the animation starts when using the down key trigger. This problem only occurs in Firefox (version 38.0.5).

If anyone has any insights into what might be causing this, I would greatly appreciate your help.

You can view the issue in action on this JSFiddle link.

Thank you for your assistance!

Answer №1

It appears that there is a bug in Firefox where the body moves up when clicked. To resolve this issue, you can add position: absolute; to the body tag.

jsfiddle example

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

Various image dimensions cause divs to shift unevenly

Here is the current setup: <div class="row"> <div class="col-md-4 content-column"> <img class="btn-center btn-desktop" src="images/buttons/btn-desktop.svg" alt="desktop button"> <h2 class="btn-deskt ...

Flowing Waterways and Transmission Control Protocol

I have a unique piece of code that I recently discovered. After running it, I can connect to it using a Telnet client. const network = require('networking'); //creating the server const server = network.createServer(function (connection) { ...

Experiencing challenges accessing information from the useEffect hook in React

I'm facing some issues with my useEffect hook and I can't seem to figure out why it's not working. I've been trying to make a call to an endpoint, but it seems like I'm not getting any response back. Any help would be greatly appr ...

I Tried Adding Up All the Numbers, but It Doesn't Seem to Work for Every Dynamic Total Field

In my project, I am utilizing Laravel 5.7 and VueJs 2.5.*. The issue I am facing is that when I input values, the Total field calculates correctly. However, when I dynamically add rows for items, the calculation only works for the first row and not for the ...

AJAX allows developers to declare variables within their code to

Here is a snippet of my JavaScript code: $(\"img.agree\").click(function() { var follow_id = $(this).attr(\"id\"); var user_id = $(\"img.user_id\").attr(\"id\"); $.ajax({ type: \"POST& ...

What steps can be taken to reduce the size of the cards in ant.design?

Currently, I am using the ant.design Card component to present messages in a chat webapp built with react/redux. However, each card is displaying too much space around the text. Is there a way to adjust the card so that it wraps the text more closely? htt ...

What is the significance of the source element in Vue3's audio element?

Playing mp3 files works in Vue 2, but not in Vue3. <template> <audio src="../file_example_MP3_700KB.mp3" controls ></audio> </template> In Vue3, the code needs to be modified as follows: <template> <audi ...

Although PhoneGap resolution remains consistent, the outcomes may vary

I seem to be facing a similar issue as discussed in this post on Stack Overflow: Screen Resolution On A PhoneGap App My problem is that I have both an iPad and an Android tablet, both with a resolution of 1024 pixels across. However, while my screen displ ...

Equal height elements - Bootstrap

Is there a way to make all elements in a list the same height, even if one element has more text than the others? I've been using divs for this purpose, but I'm open to switching to li items. Any advice on the best approach? I'm currently w ...

What is the best way to achieve consistent width in a material-ui card component?

How can I ensure that all these cards have the same width? https://i.stack.imgur.com/Ns3zw.png I'm experiencing an issue with achieving uniform card widths when using flexbox in material-ui. How can I resolve this? Is it necessary to utilize Grid fo ...

React-dnd supporting multiple draggable and droppable elements

I am facing a challenge with making multiple elements draggable using react-dnd. I have an array of 4 fields that I would like to make draggable, but when I map through the array and give each element a className of 'element', they do not move as ...

The original items are not utilized by jquery-ui autocomplete

I currently have the following setup: class Team { constructor(data) { this.id = data && data.id || null this._title = data && data.title || null } get title() { return this._title } set title(v) { this ...

What is the proper way to provide login information for a webservice through a jquery ajax request?

I've been attempting to make an AJAX call using jQuery like this: $.ajax({ url: WEBSERVICE_URL, type: "GET", dataType: "application/json; charset=utf-8", username: "admin", // Most SAP ...

Error message: "An issue occurred: Unable to access undefined properties (specifically, borderRadius) in MUI react."

I recently created a navigation bar with an integrated search bar component. The styling for my search component was done using MUI styled from @emotion/styled in MUI library, where I applied a borderRadius: theme.shape.borderRadius. However, I encountere ...

Removing the root component in ReactJS can be done on specific pages by implementing

Is there a way to remove the <header/> and <footer/> components from my signup.js and signin.js pages without altering the root index.js file? Presently, the root index.js file looks like this: class Template extends React.Component { render( ...

Obtain information stored locally when an internet connection is established

I'm currently facing an issue with my Local Storage data retrieval process in Vuejs while being online. My ToDo app setup consists of Vuejs, Laravel, and MySQL. When the internet connection is available, I store data in localStorage. The ToDo app has ...

Flatbuffers does not exist in this context

Currently, I am working on a nodeJs application that involves the use of Google Flat Buffer. After installing flatc on my MacBook Pro, I compiled the schema below: namespace MyAlcoholist; table Drink { drink_type_name: string; drink_company_name: stri ...

Create an HTML table to view JSON data from a cell on a map

Looking to transform the JSON data into a table by organizing the information based on supplier and product. Below is the JSON input and code snippet: $(document).ready(function () { var json = [{ "Supplier": "Supplier1", "Product": "O ...

Efficiency of Promise-based parallel insert queries in MySQL falls short

I have developed a code in Node.js to execute insert queries using Promise.js but unfortunately, I am encountering an exception stating "Duplicate Primary Key" entry. Here is the snippet of the code: var Promise = require("promise"); var mySql = requir ...

The animation in Material UI does not smoothly transition with the webkit scrollbar

I've been experimenting with CSS animations in Material UI's sx property to achieve a webkit scrollbar that eases in and out. However, instead of the desired effect, the scrollbar appears and disappears instantly. Whether I define the keyframes ...