[jQuery] Re: Animate Variable Concatenate Help
$(this).animate({ width: mywidth + px }); think: var newwidth = { width: mywidth + px } Regards On Thu, Apr 30, 2009 at 5:54 PM, paper_robots mresto...@gmail.com wrote: I'm trying to get the width of an element, animate it bigger, then shrink it back to normal size on hover. Here's my function: $('a.slider').hover(function(){ var mywidth = $(this).width(); $(this).animate({width: 240px}); }, function(){ $(this).animate({width: +mywidth+px}); }); The line I'm having trouble with is: $(this).animate({width: +mywidth+px}); I know its not concatenated right, but I tried a few ways and couldn't get it to work. What am I doing wrong? Thanks in advanced!
[jQuery] Re: Animate Variable Concatenate Help
I tried that initially. It didn't work. I think my variable isn't being recognized by the second half of my function. I get this error in firebug.. mywidth is not defined. But if I alert it in the upper half I get a value. On Apr 30, 2:15 pm, pete higgins phigg...@gmail.com wrote: $(this).animate({ width: mywidth + px }); think: var newwidth = { width: mywidth + px } Regards On Thu, Apr 30, 2009 at 5:54 PM, paper_robots mresto...@gmail.com wrote: I'm trying to get the width of an element, animate it bigger, then shrink it back to normal size on hover. Here's my function: $('a.slider').hover(function(){ var mywidth = $(this).width(); $(this).animate({width: 240px}); }, function(){ $(this).animate({width: +mywidth+px}); }); The line I'm having trouble with is: $(this).animate({width: +mywidth+px}); I know its not concatenated right, but I tried a few ways and couldn't get it to work. What am I doing wrong? Thanks in advanced!
[jQuery] Re: Animate Variable Concatenate Help
There is no second half of my function, those are two distinct functions. A variable declared with 'var' in the first one isn't available to the second (without the 'var' it's global and would be available, but that's not recommended). You can use .data() to store the width and retrieve it in the second function. On Apr 30, 12:38 pm, paper_robots mresto...@gmail.com wrote: I tried that initially. It didn't work. I think my variable isn't being recognized by the second half of my function. I get this error in firebug.. mywidth is not defined. But if I alert it in the upper half I get a value. On Apr 30, 2:15 pm, pete higgins phigg...@gmail.com wrote: $(this).animate({ width: mywidth + px }); think: var newwidth = { width: mywidth + px } Regards On Thu, Apr 30, 2009 at 5:54 PM, paper_robots mresto...@gmail.com wrote: I'm trying to get the width of an element, animate it bigger, then shrink it back to normal size on hover. Here's my function: $('a.slider').hover(function(){ var mywidth = $(this).width(); $(this).animate({width: 240px}); }, function(){ $(this).animate({width: +mywidth+px}); }); The line I'm having trouble with is: $(this).animate({width: +mywidth+px}); I know its not concatenated right, but I tried a few ways and couldn't get it to work. What am I doing wrong? Thanks in advanced!