user1646428
user1646428

Reputation: 179

callback functionality needed

I'm trying to construct a JavaScript function that accepts a transition function as one of its parameters. Keep in mind that this transition function is user built so it will have a variety of syntax, but the goal of this function is to transition the webpage from one style to another.

For example, the page might currently have a vertical three column layout and calling this transition function might change it into a horizontal two column layout.

What I need is some type of callback or wait/sleep function until the transition is complete (which is designated by the presence of a particular form object). I've been trying to use eval(), but have read several many posts on not using this. Below is an example of the code I'm looking for - no jquery or other framework please.

// MAKE ANY WEBPAGE TRANSITIONS
if (transition != '') {
    eval(transition, callback) {
        success: alert('done with the transition eval call');
    }
}

Upvotes: 0

Views: 44

Answers (1)

Quentin
Quentin

Reputation: 943601

The transition function has to be designed to accept a callback in the first place.

function transition(callback) {
    // Do stuff
    callback();
}

transition(function () { alert("end of transition"); });

There is no generic way to detect when a function which performs asynchronous actions (such as Ajax or setTimeout calls) has finished. The function itself has to provide a way.

Upvotes: 2

Related Questions