CSS Transition fails to trigger upon adding a class to the body in Firefox

I have been working on a website where I want to create a sticky header that reduces the padding of two elements once the user starts scrolling. To achieve this, I have added a class to the body tag when scrolling begins and set up transitions to animate these changes. While this works smoothly in webkit browsers, I am facing difficulties with Firefox. Here is a JSFiddle illustrating the problem: http://jsfiddle.net/5HLyu/11/. Any assistance would be greatly appreciated!

HTML

<body>
<div class="header-wrapper">
    <div class="header">
        Header
    </div>
    <div class="menu">
        Menu
    </div>
</div>
</body>

CSS

body{height:1000px; overflow:scroll; padding:0; margin:0}
.header{background:#00457c; color:#fff; padding:22px 0; text-align:center;
    -webkit-transition:all 250ms ease-out;
    -moz-transition:all 250ms ease-out;
    -ms-transition:all 250ms ease-out;
    -o-transition:all 250ms ease-out;
    transition:all 250ms ease-out;
}
.menu{background:#aaa; padding:22px 0; text-align:center;
    -webkit-transition:all 250ms ease-out;
    -moz-transition:all 250ms ease-out;
    -ms-transition:all 250ms ease-out;
    -o-transition:all 250ms ease-out;
    transition:all 250ms ease-out;
}

.down .header-wrapper{position:fixed; top:0; width:100%; z-index:1000}
.down .header{padding:10px 0}
.down .menu{padding:10px 0}

jQuery

(function($){
    $(window).on("scroll", function() {
        var fromTop = $(window).scrollTop();
        $("body").toggleClass("down", (fromTop > 1));
    });
})(jQuery);

Answer №1

It appears that there are some issues with transitions in FF when the position of an element is changed.

Make this adjustment:

.down .header-wrapper{position:fixed; top:0; width:100%; z-index:1000}

Change to:

.header-wrapper{position:fixed; top:0; width:100%; z-index:1000}

(i.e., remove the .down selector)

I believe this modification won't have any adverse effects on your code.

Check out the demo here

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

Validating Password Consistency using Javascript

I'm having trouble with validating the password fields and ensuring they match, even when both input boxes contain the same password. JavaScript var validator = $("#signupform").validate({ rules: { password: { required: true, minle ...

Issue with aligning CSS in Internet Explorer 7

Everything looks great on Firefox and IE8, but on IE 7 the middle "search input text field" is not aligned properly with the other two fields. It seems to be dropping down slightly. Here is the code - thank you for your help: <!DOCTYPE html PUBLIC "-/ ...

Creating sitemaps for multi domain websites using NextJS

We are implementing a next-sitemap package to generate sitemaps for our Next.js pages located in the /pages directory. For pages that come from the CMS, we use server-sitemap.xml with SSR. Despite having 6 different domains, we manage them within a single ...

Locating the save directory with fileSystem API

I've been working on saving a file using the fileSystem API. It appears that the code below is functional. However, I am unable to locate where the saved file is stored. If it's on MacOS, shouldn't it be in this directory? /Users/USERNAM ...

Reordering images using jQuery leads to a malfunctioning reloading of images

I am in search of the most effective approach to alter the src attribute for multiple images on a page post-loading. Essentially, I need to reorganize them for better display. In their initial arrangement, they are presented as follows: 1 5 9 2 ...

What happens to CSS specificity when JavaScript is used to change CSS styles?

When JavaScript modifies CSS, what is the specificity of the applied styles? For example: document.getElementById("demo").style.color = "red"; Would this be deemed as inline styling? ...

What is the best way to align two HTML elements in a single column?

I need to adjust the layout of an existing <td> in order to display a checkbox and one additional field on the same line. The current setup places these elements on separate lines. Below is the provided HTML code: <!DOCTYPE html> <html> ...

The jQuery UI datepicker struggles to show the entire year in its year selection menu

Recently, I developed a function within an MVC Struts application's JSPs that sets up a generic jQuery-UI datepicker. Here is the code: function setUpGenericDate(id) { var d=new Date(); $("#" + id).datepicker({ duration: 'fa ...

Retrieve a JSON file from a different tab or window

My setup includes two servers: one dedicated to hosting HTML content and the other functioning as an API for connecting to Twitter. To initiate the process, I open a new tab (or window) on the HTML Server to invoke the API, which then redirects to the T ...

I am in need of a datepicker for my project that will display the END date as the current date and set the START date as 7 days before the END date

$(document).ready(function () { $("#end").datepicker({ dateFormat: "dd-M-yy", minDate: 0, onSelect: function () { var start = $('#start'); var startDate = $(this).datepicker('getDate') ...

Create a Material Design Lite Grid layout featuring cards that mimics the aesthetic of Google Keep

My current project involves using Django along with Material Design Lite to create a responsive layout. The cards I generate adjust their size based on the screen width. To demonstrate this, here is a snippet of the HTML code with some cards removed for r ...

The validation for props is incomplete as the parameter 'match.params.id' is not present

I am currently working on a project and following a tutorial as I am still a beginner in this field However, my code is generating an error specifically at console.log(props.match.params.id); The error message reads: 'match.params.id' is missin ...

I have encountered an issue where after declaring a JavaScript variable on a specific page, including the JavaScript file does not grant access to it

<script type="text/javascript"> $(document).ready(function () { var SOME_ID= 234; }); </script> <script type="text/javascript" src="<%= HtmlExtension.ScriptFile("~/somefile.js") %>"></script> ...

Are current web browsers able to block the code "<a href="javascript:window.open....?

I am looking to create a pop-up window for sharing on Facebook. The best way to achieve this is by using javascript to pop up a small window with a width of 400 pixels and a height of 200 pixels. Will pop-up blockers in Chrome, IE, or Google block this f ...

Utilize font styles for individual HTML symbol entity (&trade;) on your website

I have customized my WordPress theme to use Montserrat for titles and Open-Sans for body content. However, when adding the trademark symbol ™ / &trade; to product titles, it appears in a different font style similar to Times New Roman. Is there ...

Switching charset/encoding on load() using jQuery

Query: How can the encoding of a text file being loaded through jQuery's load() function be adjusted? I previously had a single page, index.html, where I consolidated all my css, js, and html content. Now, I aim to separate the header section from th ...

Swapping icons in a foreach loop with Bootstrap 4: What's the most effective approach?

I need a way to switch the icons fa fa-plus with fa fa-minus individually while using collapse in my code, without having all of the icons toggle at once within a foreach loop. Check out a demonstration of my code below: <link rel="stylesheet" href= ...

What is the best way to ensure the hamburger menu stays perfectly centered?

My menu is currently aligned to the right and scrolls with the user profile. I want the menu to always be centered and the profile to stay on the right side. I am working with Angular 12 and Bootstrap 5 for this project. Here is the code I have been usin ...

Transfer information using the Ajax jQuery technique

I would greatly appreciate your assistance. Can you please help me with one more thing? I have the code below and I am having trouble figuring out where I am making a mistake: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.j ...

Having trouble with replacing an entire div selector with a new div after using Jquery's .html method?

I've searched high and low, but can't find a reference. However, this should be obvious. Two select lists If the result of the first list is Australia, then keep the second list. If it's not Australia, replace the second list with an inpu ...