<button onclick="$.MyObject.add('wrapper');">Add</button>
Somewhere in the code I did:
$.MyObject= new MyUberObject();
then in my add function, I specify my call back, and invoke the animation and pass my callback to it.
function MyUberObject(data) {
...
this.add = function(name, index) {
var callback = function(n,i) {
$.MyObject.addDiv(n, i);
alert("wtf");
}(name, index);
$("#outerWrapper").animate(
{
"width": "+=200px",
},
{
duration : "fast",
easing: "linear",
complete: callback
}
);
...
}
However the alert come up immediately as soon as the button is pressed, then once I cleared the alert, the animation would go… I’ve tried many different ways of specifying the callback, as well as try to use delay and call it in other places… still no go.
You are calling the callback here, that’s why it’s getting called.
Try doing this, I think name and index should exist due to closure.
if not then you can add the name and index to the outerwrapper:
or maybe even simpler…