The animation does not reoccur in Firefox when using Modal

I have a unique issue with my modal that displays images, where the animation only works the first time on Firefox. When I open the modal for the first time, everything works perfectly, but if I close it and then reopen it, the animation no longer plays. Interestingly, this problem does not occur on Chrome.

HTML

<img src="https://s-media-cache-ak0.pinimg.com/236x/e8/2e/cc/e82ecc7ea98248bfa8161dcfcef2974a.jpg" id="postimage"></img>

 <div id="myModal" class="modal">
  <span class="close" onclick="document.getElementById('myModal').style.display='none'">&times;</span>
  <img class="modal-content" id="modalImage">
</div>

CSS

.modal {
    display: none; 
    position: fixed; 
    z-index: 999999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.8); 
}
#postimage:hover {
    opacity: 0.8;
    cursor: pointer;
}

.modal-content {
    display: block;
    width: 100%;
    margin: auto;
    max-width: 720px;
}

@-webkit-keyframes fadeIn {
    from {opacity:0.0}
    to {opacity:1}
}

@keyframes fadeIn {
    from {opacity:0.0}
    to {opacity:1}
}

.modal-content {
    -webkit-animation-name: fadeIn;
    -webkit-animation-duration: 1.8s;
    animation-name: fadeIn;
    animation-duration: 1.8s;
}
.close {
    position: absolute;
    top: 50px;
    right: 50px;
    color: #e3e3e3;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.close:hover,
.close:focus {
    cursor: pointer;
    color: #787878;
}

JS

var modal = document.getElementById('myModal');

var img = document.getElementById('postimage');
var modalImg = document.getElementById("modalImage");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
}

var span = document.getElementsByClassName("close")[0];

span.onclick = function() {
  modal.style.display = "none";
}
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}

JSFIDDLE

Answer №1

Consider including the following code:

@-moz-keyframes fadeIn {
  from {
    opacity: 0.0;
  }
  to {
    opacity: 1;
  }
}

Make sure to update the .modal-content with the following:

  -moz-animation-name: fadeIn;
  -moz-animation-duration: 1.8s;
  -moz-transition-timing-function: ease-in;
  -moz-animation-iteration-count: 1;
  -moz-animation-fill-mode: both;

-moz- is specifically designed for Firefox, just like -webkit- is for Chrome or Opera. This information can be found on this website

For more details on transition-timing-function, which controls the acceleration of the animation, enabling speed adjustments over various durations.

Learn about animation-iteration-count, which determines how many times an animation cycle will play before stopping.

Lastly, explore animation-fill-mode, which affects how the animation applies styles to the specified target.

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

Unable to retrieve a string from one function within another function

Three functions are responsible for triggering POST API calls, with the intention of returning a success or failure message to whoever invokes them (Observable<string>). In an effort to avoid repetition, I introduced a new function to retrieve succe ...

Is it possible to deselect a checkbox in a Datagrid Material-ui by clicking a button?

I have set up a grid in Datagrid Material-UI with a checkbox. I am trying to figure out how to uncheck the checkbox by clicking a reset button after it has been checked. For example: https://i.sstatic.net/Za1E6.png This is the DataGrid code I currently ...

What is the best way to add an element after a specific child element with jquery?

Is there a way to add a paragraph element after a specific div class element? I am looking to include a p element within the second text div class. I attempted a solution, but it is not producing the desired result. The current solution is not effective. ...

Sending a list of data using ajax to an external PHP script for deferred rendering in datatables

I've set up a form on one of my pages that features check boxes linked to the primary id of certain information that is retrieved on another page based on whether the check box was checked or not. After switching to jquery-datatables with deferred ren ...

Guide on saving the highest score in a game using JavaScript with an if statement

I am currently working on a practice game that involves counting the number of taps made within 3 seconds. I've completed everything except for implementing the functionality to save the high score and display the previous best score if there isn&apos ...

Having trouble with the Three.js OBJ loader in CodePen?

Currently, I am experiencing a challenge with loading an OBJ file on Three.js. Oddly enough, the functionality seems to be working perfectly fine when I deploy the files on my server as demonstrated here: However, when attempting to run it on Codepen, I e ...

Arrange two div elements side by side so they remain adjacent even when you adjust the browser size

After years of success with my floated left and right divs, I am now facing a challenge with responsive design. No longer able to rely on fixed widths, I find that when the screen size decreases, the right div moves below the left one. I know that using f ...

Determine whether a given string is a valid URL and contains content

Is there a way to ensure that one of the input fields is not empty and that the #urlink follows the format of a URL before executing this function in JavaScript? $scope.favUrls.$add I'm uncertain about how to approach this. html <input type="te ...

Implement a vertex shader to transform a mesh's vertices without consideration of its current location

Looking to add movement to my meshes using a vertex shader, I've run into an issue where translating my meshes in the scene also affects the position of a sinus wave. The goal is to keep the sinus wave consistent across both meshes even when translati ...

What is the process of using the split() method to extract specific text from a string in JavaScript?

Working with AngularJS and facing a requirement to extract a specific text from a scope value. Here's my scope value: $scope.myLogMsg = '1111 order is placed by Sukumar Ms(User)'; //output: by Sukumar Ms(User) Desired output: by Sukumar Ms ...

Error encountered while parsing JSON data for dynamic charts in Chart.js

I am currently in the process of constructing dynamically generated graphs utilizing technologies such as Chart.js, jQuery, JSON, Mustache.js, and Twitter Bootstrap. All the data required for these graphs is stored within a JSON file, which is then used i ...

Exploring Angular 2 Routing across multiple components

I am facing a situation where I have an app component with defined routes and a <router-outlet></router-outlet> set. Additionally, I also have a menu component where I want to set the [routerLink] using the same routes as the app component. How ...

JavaScript's utilization of local variables and callback functions enables developers to enhance the

After exploring the information in this particular post, it became evident that my issue was different. While working on creating functions for managing mongoDB GridFS, I encountered a perplexing behavior that I will illustrate through a simplified example ...

AngularJS array value with HTML tags is not displaying properly upon invocation

In Angular, I have an array that has the following structure: $scope.posts = [ { "ID" : id(), "Title" : "A", "Company" : "Company A", "Location" : "San Francisco, CA", "Date" : "2016-06-20", "Description ...

A more concise method to verify if something is undefined in JavaScript

Anyone have suggestions for a more concise idiom to use? const x = module || window; // Reference Error fallback Is there a shorter method to verify the presence of module? ...

What could be the issue with trying to bind an event handler in this manner?

I'm having some trouble binding an event handler with jQuery: $(document).ready(function () { var newsScrollerForPage = new NewsScroller(); newsScrollerForPage.init(); $('#scroller-left-a').bind('on ...

What is the best way to remove unnecessary space in a div when the content is smaller than the height, while still using overflow:auto?

HTML CODE <p>overflow:auto</p> <div class="auto">This code snippet will add a vertical scroll bar to the content within the div if it exceeds the height of the div. The background color is set to green, width and height are both 100px, ...

Malfunctioning carousel

I've been attempting to set up a carousel, but it's not functioning properly. I'm unsure of where the issue lies. The navbar section is working fine, but the carousel isn't appearing at all. Should the carousel be placed above the navba ...

Step by step guide on how to connect a stylesheet in CSS

Hey there, I recently attempted to link a style sheet in my HTML for the first time. Unfortunately, I encountered an issue where it didn't work. Here's the code I used: <link href="css/StyleSheet.css" rel="stylesheet" type="text/css" /> W ...

data-abide is flagging all fields as incorrect

Recently, I encountered an issue with a specific form I have created: <%= form_for(@building_shared_space, data: {abide:''}) do |f| %> ... <div class="field"> <%= f.label :room_type, 'Room Type' %> <%= ...