开发者

.delay not working

I am relatively new to jQuery so this may be a be开发者_运维问答ginners mistake, but for some reason I can't get the .delay() function to work.

The code I am working with is:

$(document).ready(function() {                     
    $("div#main").css("opacity","0");  
    $("div#main").animate({opacity: 1}.delay(1000), 'slow');  
});

With the "jQuery 1.2.3 - New Wave Javascript" script

Can anyone point out what I am doing wrong? Thanks in advance!


I see two problems. One is that there is no delay function in jQuery 1.2.3. You'll either need to include it as a plugin or update to the most recent version of jQuery. Assuming that you've done this, the other problem is that you're calling delay on a normal JavaScript object, and not a jQuery object. You should be getting an error from trying to call a non-existent function. So instead of this:

$("div#main").animate({opacity: 1}.delay(1000), 'slow');

Use this:

$("div#main").delay(1000).animate({opacity: 1}, 'slow');

This inserts a one second delay in the animation queue that will be executed before the opacity animation is triggered.


There's nothing wrong with the code you're showing here. Did you place the whole thing in a document ready handler so that it will only execute when the DOM is ready for manipulation?

$(document).ready(function(){
    $("div#main").css("opacity","0").delay(1000).animate({opacity: 1}, 'slow');
});

See: http://www.jsfiddle.net/yijiang/cRqwd/ for a simple example of your code working.


Edit: I assume you're looking at this: http://allforeveryone.blogspot.com/2008/03/jquery-new-wave-javascript.html. In case you have not noticed, that is an incredibly old version of jQuery you're working with there. delay() was only introduced in version 1.4. Go to http://jquery.com to download the latest version.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜