Enhance user experience with CSS animations and automatic page reloading on the previous page for both iOS and Android

I need help finding a solution for a transition effect I am implementing in my project. The effect I want to achieve is as follows:

  • Page fades in with an opacity that transitions from 0 to 1 using @keyframes
  • When any link is clicked, the page opacity goes back to 0 through another set of @keyframes
  • I have included an event listener for animationEnd which sets the page opacity to 0 to prevent a strange flash and then proceeds to follow the link.

While this works well on Chrome, Firefox, and IE, I am experiencing difficulties on iOS and Android. When users hit the "back" button, the page reloads with its previous state (opacity: 0). I suspect this may be a built-in feature that prevents CSS/JS from reloading, but it's frustrating because I can't figure out how to refresh assets when going back.

Has anyone discovered a reliable solution for this issue?

--

For reference, here is a snippet of my current JS code:

if ("animation" in document.body.style) {
    var animationEnd = "animationend"
}
else {
    var animationEnd = "webkitAnimationEnd"
}

var links = document.querySelectorAll('a');
for (var i = 0; i < links.length; i++) {
    links.item(i).addEventListener("click", function(e) {
        var targetLink = this.getAttribute('href');
        if (targetLink != '#') {
            e.preventDefault();
            page.className += ' ' + 'fadeout';
            var fadeoutElement = document.querySelector('.fadeout');
            fadeoutElement.addEventListener(animationEnd, function() {
                this.style.opacity = '0';
                window.location.href = targetLink;
            });
        }
    });
}

Answer №1

To enhance the performance of your code, consider enclosing the section you wish to "refresh" within pageshow:

window.addEventListener("pageshow", function() {
  ... insert your code here ...
}, false);

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

"When using Webpack and Sass, the background image specified with background: url() is processed correctly. However, when using webpack-dev-server, the image is

Currently, I am utilizing Webpack 2 in conjunction with webpack-dev-server and Sass loader. Here is my current configuration: { test: /\.scss/, loaders: [ "style", { loader: "css", query: { modules: false, sourceMap: true } }, ...

Has anyone successfully intercepted the Android BLE MTU measurement?

Currently conducting cross-platform analysis on the parameters related to BLE on Smartphones. I have already examined the ATT_Exchange_MTU_Req/Rsp for iOS devices. Anyone here tried sniffing the same for Android and found a value? ...

Enhancing Image Quality with jspdf and Html2Canvas

We are currently utilizing jsPDF and HTML2canvas to create PDFs, however, we have noticed that the image resolution is quite high. Is there a method available to obtain low-resolution images using jquery, javascript, jsPDF, and html2canvas? function addE ...

Creating a hierarchical tree structure from tabular data with JavaScript ECMAScript 6

Seeking a JavaScript algorithm utilizing ECMAScript 6 features to efficiently convert JSON table data into a JSON tree structure. This approach should not employ the traditional recursive algorithm with ES5, but rather emphasize a functional programming me ...

The idea of a GPS tracking software malfunctioning and crashing

Good evening and happy new week! We followed the tutorial but encountered a crash issue without any specific error in the code. We would greatly appreciate your assistance. Tutorial: 01-26 15:36:06.751: I/Process(10528): Sending signal. PID: 10528 SIG: ...

By default, make the initial element of the list the selected option in an AngularJS select input

I'm running into an issue with setting the first element in my ng-repeat list within a select input. Here is the code snippet causing the problem: <div> <span >OF</span> <select ng-model="eclatementCourante.ordreFabricationId" n ...

Adding x days to a Unix timestamp can be achieved by converting the Unix timestamp

Currently, I have the following code snippet: let currentTS = Math.floor(+new Date() / 1000) This code successfully retrieves the current date in a unix timestamp. However, my goal now is to append an additional 14 days to this unix timestamp. Could some ...

ng-grid automatically resizing columns based on content width

I am currently utilizing AngularJS ng-grid and endeavoring to accomplish the following tasks: 1. Adjust column width dynamically based on the content within each column. 2. Automatically resize the last column to fill the remaining space when hiding column ...

Exploring the Possibilities of Greensock within Meteor Templates

Attempting to add animation to a div within a Meteor template using TweenLite with the gsop package installed. The template html code: <template name="mainInit"> <div id="teaContainer"> <h1>Tea</h1> </div> </template& ...

Guide on Creating a Popup Window When the User's Cursor Moves Beyond the Webpage Boundary

Imagine you're browsing a webpage and as you move your mouse towards the "back" button, a window pops up within the webpage area, displaying important information. This is a clever way to grab the user's attention before they leave the website. B ...

Is the Pure CSS hide/show technique using radio buttons causing a challenge with parent and descendant elements?

Exploring a CSS Show/Hide functionality using radio buttons is my current challenge. The snippet below demonstrates how smoothly it works. .refusal, .acceptance { display: none; } input#refusal:checked~.refusal { display: block; } input#acceptanc ...

Properly Positioning Text within React's Material UI Components

I am encountering a simple issue where I am trying to align '01/01/2020' with 'A00002'. To view my code on CodeSandbox, please visit CLICK HERE <div className={classes.root}> <Typography variant="h6" className={cla ...

Component is not rendering with React-router

Having some trouble with this code snippet I'm trying to implement. React is not rendering the component and I can't figure out why. I have included react-router from a CDN. Any assistance would be greatly appreciated. import { Router, Route, Li ...

Orientation-specific sensor values

I am using OrientationEventListener() to detect orientation changes, but I am getting continuous values. I only want to detect four values for each orientation: PORTRAIT, REVERSE_PORTRAIT, LANDSCAPE, and REVERSE_LANDSCAPE MODE. How can I ensure that I only ...

Animating jQuery Counter with Changing Background Color

I've implemented a Counter that counts from 0 to a specified number, and it seems to be working perfectly. However, I want to add an animation where the background color of a div height animates upwards corresponding to the percentage of the counter. ...

Load the view controller without showing the interface defined in the nib file

I have a scenario where I need to automatically log in a user using cached tokens without them having to tap a button. Currently, when the view loads, the login process happens seamlessly and dismisses the view immediately. However, I want to find a way to ...

How can React hook state be efficiently utilized in a debounced callback?

function Foo() { const [state, setState] = useState(0); const cb = useCallback(debounce(() => { console.log(state); }, 1000), []); return ...; } In the code snippet above, there is a potential issue where the state variable may become outda ...

Tips for selecting the correct date on a DatePicker using selenium?

I am facing an issue with my selenium test related to a date picker on a webpage. The task is to select a specific date (e.g., 14/2/2012) by clicking on the correct day. However, the date picker is generated using jQuery as shown in the code snippet belo ...

Filtering out strings of a certain length from an array in JavaScript

Currently working on creating a Wordle game using React. To do this, I require a list of strings. To obtain this list, I am fetching an array of strings from the following API: The challenge lies in the fact that I am interested only in words with a lengt ...

javascript trigger not functioning

Currently, I am working with ASP development and incorporating jQuery into my projects. One challenge I've encountered is not being able to utilize the trigger function upon page load. Interestingly, my change function seems to work smoothly, except ...