Maintaining an onExit function in the ui-router framework

I am trying to implement an animation on an element within a page when the user is transitioning out of a state. Here is my current code snippet:


{
    .....,
    views: { ... },
    onExit: function(){
        someEle.classList.remove("someClass");   //CSS transition
    }
}

However, the view of the exiting state gets destroyed instantly when the state change happens, resulting in no animation being displayed. Is there a way to delay the exit of the state for a specific duration to allow the animation to complete?

Answer №1

Take a look at this latest approach, incorporating click events on <a> elements. By effectively preventing the event from activating during the transition period, and successfully resetting the defaultPrevented property of the event while dispatching it from the transitionend event, I was able to address an issue where the event was not redirecting to the link URL even though it was firing due to a subsequent transition on the link.

To resolve this matter, I accessed the target.href property of the event. Feel free to review the code snippet below:

Pure JS:

var links = document.getElementsByTagName("a");
function onTransitionEnd(event) {
    window.location.href = event.target.href;
}
for(i=0; i<links.length; i++) {
    links[i].addEventListener("click", function(e) {
        this.addEventListener("transitionend", function() {
            onTransitionEnd(e);
        });
        if( this.className.search(/animate/) > -1 )
            this.className = this.className.replace("animate", "");
        else
            this.className = this.className + " animate";
        e.preventDefault();
    });
}

Pure JS Fiddle.

Using jQuery:

function onTransitionEnd(event) {
    console.log(event);
    window.location.href = event.target.href;
}
$("a", this).on("click", function (e) {
    if ( $(this).hasClass("animate") )
        $(this).removeClass("animate");
    else
        $(this).addClass("animate");
    $("a").on("transitionend", function () {
        onTransitionEnd(e);
    });
    e.preventDefault();
});

jQuery Fiddle.

With Original Poster's Code (Pure JS):

function onTransitionEnd(event) {

    /* do stuff here */

}

{
    .....,
    views: { ... },
    onExit: function(e){
        someEle.addEventListener("transitionend", function() {
            onTransitionEnd(e);
        });
        someEle.classList.remove("someClass");   //CSS transition
    }
}

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

Learn the steps to showcase the output in a paragraph using ReactJS

Is there a way to display the result in the browser instead of just exporting it to the console when using the code below? I am new to React and would like the result to appear in a paragraph or another tag on the webpage. import React, { Component, use ...

I am experiencing difficulty with the color of my progress bar in Firefox

After successfully creating an interactive progress bar that works perfectly in Google Chrome and surprisingly also in Safari without vendor prefixes, I encountered a roadblock when testing it on Firefox. The progress bar color reverts back to the default ...

Transferring information between AngularJS and Angular applications

Having two applications on localhost: http://localhost/testsite (Angular js app) http://localhost:4200 (Angular app) Seeking assistance in sharing data from Angular JS to Angular application. Any guidance would be appreciated. Thank you. ...

Nested Angular Controller in a ng-repeat loop

I am attempting to utilize a nested controller within an ng-repeat in order to have the accordion panels on the page function in different scopes. However, I am encountering a problem where the code inside the nested controller is not being executed. I pla ...

Create sleek and custom forms with AngularJS and JQuery

As a core C++ developer, I have recently expanded my skills to include Scala, Lift, and AngularJS. My latest project involves developing an application similar to . There is a high possibility of needing to modify existing features or introduce new ones t ...

Dealing with JavaScript errors within an Express application

Consider the following async function export async function fetchData() { const result = await fetchData(); return result[0].id; } In the route, there is router.post( '/some-route', handleAsyncError(async (req: Request, resp: Response, _ ...

Eliminating pre-set CSS styles injected in Angular 2/Ionic 2 automatically

I'm encountering an issue where adding the ionic 2 gesture (press) to a button results in inline styles being automatically applied to that button. Is there a way to override the styles it adds? Button <button ion-button (press)="toggleFavourite ...

Leveraging google transliteration within a Flex environment

Here is an illustration of how the Google transliteration feature can be utilized in specific HTML textboxes. I am looking to incorporate this same functionality for a Flex application. Is there a method through which this can be achieved? <html> ...

Generating a live HTML preview using Kendo Editor within an Angular framework

Currently, I am in the process of integrating the Kendo UI Editor with Angular, following the example showcased on their demo site. The implementation has been smooth so far; explore Kendo UI demos here Although everything seems to be functioning well up ...

Insufficient Resources Error (net::ERR_INSUFFICIENT_RESOURCES) encountered while executing jQuery script with multiple ajax requests for 2 minutes

Upon initially loading the code below, everything seems to be functioning smoothly with the dayofweek and hourofday functions. However, shortly thereafter, the browser (Chrome) freezes up and displays the error message: net::ERR_INSUFFICIENT_RESOURCES. Thi ...

How can I use a button to save all changes made in a JqGrid checkbox column simultaneously?

In my jqgrid, there is a column named 'asistencia' which displays data from a database as checkboxes. These checkboxes are pre-checked based on the property formatoptions: {disabled : false}. I would like to implement a 'save' button th ...

How can I dynamically assign ng-model with a filter for a particular object in an array?

Is there a recommended method for linking an input element to a specific field of an object in an array using its id? I tried using ng-model along with the find() function from the array prototype. However, the implementation is not working properly as it ...

The audio directory is not included in the build of the Ionic framework, causing it to be skipped and absent

Recently, I've been working on an Ionic/Cordova app and came across a folder labeled /audio which consists of mp3 files: /www /assets /audio file.mp3 /css /js config.xml index.html The issue at hand is that the /audio directory is n ...

The 'disabled' property is not found in the 'MatButton' type, however, it is necessary in the 'CanDisable' type

Issue found in node_modules/@angular/material/core/option/optgroup.d.ts: Line 17: Class '_MatOptgroupBase' does not correctly implement interface 'CanDisable'. The property 'disabled' is missing in type '_MatOptgroupBas ...

Deactivate a span in real-time using ng-model

I found a helpful guide on creating a custom editable <span> using ngModelController here: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#example Now, I am looking to implement a feature that allows me to dynamically disable editin ...

Add option button

Is there a way to dynamically add radio buttons using jQuery or JavaScript and save the data into a database? I have successfully appended input types such as text, textarea, checkbox, and select with options. Here is my code: <!DOCTYPE html> < ...

How require works in Node.js

My current database connection module looks like this: var mongodb = require("mongodb"); var client = mongodb.MongoClient; client.connect('mongodb://host:port/dbname', { auto_reconnect: true }, function(err, db) { if (err) { ...

I am having trouble with my jQuery login function not properly connecting to the PHP file

Hey there, I've been working on creating a login system from scratch by following an online tutorial. The initial Javascript is functioning properly as it detects errors when the inputs are empty. However, once I enter text into the input fields and c ...

How to Link Laravel 5 with Ajax?

I've implemented this Laravel code in my controller for the detach function. $input = Input::all(); $product= Products::findOrFail($input['product_id']); $product->tags()->detach($input['tag_id']); $product= Prod ...

ChessboardJs: JavaScript Boards Function Properly on Initial Use Only

Update: The page code can be accessed via my page URL. I'm unsure where the issue lies. Your assistance is appreciated. Issue: Initially, when clicking on the chess puzzles page, everything works fine. However, upon re-clicking from the homepage, th ...