homepage Welcome to WebmasterWorld Guest from 54.211.73.232
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
adding a variable
ctoz

5+ Year Member



 
Msg#: 4294876 posted 5:16 am on Apr 10, 2011 (gmt 0)

It's a primitive bit of scripting, but it works:

function gray() {
$('.A1').animate({color:"#999"}, 400);
setTimeout('$(\'.A1\').animate({color:"#3a3d3f"}, 1600)', 600);
setTimeout('$(\'.A1\').fadeOut(\'100\')', 2600);
}

So, how to turn the class a variable? I'm halfway there with:

function gray(myclass) {
$(myclass).animate({color:"#999"}, 400);
setTimeout('$(myclass).animate({color:"#3a3d3f"}, 1600)', 600);
setTimeout('$(myclass).fadeOut(\'100\')', 2600);
}

called with
gray('.A1')

The first animation fires, but the second and third don't;
FF error console is saying " myclass is not defined " for the second and third lines, but not for the first.

I'm tinkering, but could do with some insight !

 

daveVk

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4294876 posted 8:12 am on Apr 10, 2011 (gmt 0)

either
setTimeout('$(\'' + myclass + '/').animate({color:"#3a3d3f"}, 1600)', 600);

or

setTimeout(function(){$(myclass).animate({color:"#3a3d3f"}, 1600)}, 600);

ctoz

5+ Year Member



 
Msg#: 4294876 posted 10:45 am on Apr 10, 2011 (gmt 0)

Many thanks!

setTimeout(function()... works fine and I understand it. Not clear about the forward slash in the first option.

cheers!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved