开发者

How to place different JQuery codes in one line?

How can I put this in one line?

$("#welcome").delay(100).fadeIn('slow').开发者_开发知识库delay(100).$("#slogan").slideDown(1000);

The following code works:

$("#welcome").delay(100).fadeIn('slow').delay(100);

but not if I place the slogan code after it.


Use callback function of delay()

$("#welcome").delay(100).fadeIn('slow').delay(100, function(){
     $("#slogan").slideDown(1000);
});


$.("#slogan") is not a method which you can chain after the rest of the methods...so no, this would not work. I guess what you want is to use a callback function like so:

$("#welcome").delay(100).fadeIn('slow').delay(100, function(){
   $("#slogan").slideDown(1000);
});

What this does is, call the slideDown for #slogan after the delay on #welcome is finished.


by adding a anonymous function after the delay like this:

$("#welcome").delay(100).fadeIn('slow').delay(100, function() {$("#slogan").slideDown(1000) });


The effects functions all take a callback optional argument:

 $("#welcome").delay(100).fadeIn('slow', function() {$("#slogan").delay(100).slideDown(1000);});


You can't append a second selector like that. If #slogan is a child of #welcome you can use

$("#welcome").delay(100).fadeIn('slow').delay(100).children("#slogan").slideDown(1000);

though.


If slogan is a descenedant of welcome you could do:

$("#welcome").delay(100).fadeIn('slow').delay(100).find("#slogan").slideDown(1000);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜