Thanks alot dabear thank works perfectly (despite looking a little
crazy ;) .
On 16 Oct, 14:12, dabear <[EMAIL PROTECTED]> wrote:
> So if I understand you correctly, you want to preserve some variables
> from the sorrounding scope? What about using a one-off function
> (anonymous function immediately executed) that returns a function?
>
> var foo=someValue;
>
> $(el).animate( css, speed, (function(arg1){ return function()
> { use arg1 here} ;})(foo) );
>
> foo=someOtherValue;
>
> This ensures that arg1 can be manipulated inside the callback, without
> effecting the outer value of foo
>
> On Oct 15, 7:09 pm, weepy <[EMAIL PROTECTED]> wrote:
>
> > It will work if there's no change to my_z_index whilst the animation
> > takes place.
>
> > e.g.
>
> > var my_z_index = 10
>
> > $(el).animate( css, speed, function(){
> > alert(my_z_index)
>
> > });
>
> > my_z_index = 1000
>
> > => alert(1000)
>
> > The problem being that the behaviour of the function is determined by
> > factors outside of it's scope.
>
> > I was hoping for something similar to the way window.setTimeout works
>
> > window.setTimeout(
> > function(arg1,arg2) {}
>
> > }, 100, arg1, arg2 etc );
>
> > Of course I can simulate this by doing
>
> > $(el).animate( css, speed)
>
> > window.setTimeout(function(el, z){
> > $(el).css(zIndex, z)
>
> > }, speed, el, my_z_index);
>
> > But I was hoping there was a better way :)
>
> > weepy
>
> > On 15 Oct, 17:43, "John Resig" <[EMAIL PROTECTED]> wrote:
>
> > > Change the ':' to a ',' and that will work exactly as you advertise it to:
>
> > > var my_z_index = 10
>
> > > $(el).animate( css, speed, function(){
> > > $(el).css(zIndex, my_z_index)
>
> > > });
>
> > > --John
>
> > > On Wed, Oct 15, 2008 at 12:40 PM, weepy <[EMAIL PROTECTED]> wrote:
>
> > > > I have variables in the scope that i'm calling jQuery
>
> > > > - won't they be lost inside the anonymous function ?
>
> > > > E.g. how do I do this :
>
> > > > var my_z_index = 10
>
> > > > $(el).animate( css, speed, function(){
> > > > $(el).css(zIndex: my_z_index)
> > > > });
>
> > > > On 15 Oct, 17:16, "mike.helgeson" <[EMAIL PROTECTED]> wrote:
> > > >> $(el).animate( css, speed, function(){
> > > >> callback.apply( this, [ arg1, arg2, ...] );
> > > >> });
>
> > > >> On Oct 15, 11:46 am, weepy <[EMAIL PROTECTED]> wrote:
>
> > > >> > Hi
>
> > > >> > I want to run a function on completion of an animation
> > > >> > I want to pass in arguments to this function. Is this possible ?
>
> > > >> > e.g.
>
> > > >> > $(el).animate(css, speed, function callback(args to pass in) { /* do
> > > >> > stuff */) )
>
> > > >> > Any one know how to do this ?
>
> > > >> > cheers
>
> > > >> > weepy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---