I am using this code to delay the entrance of an element to the viewable area of the screen, but the first animate is wholly unecessary, other than to start a queue that delay can then delay.
$("#top-message").animate({top: '-500px'},400).delay(1000).animate({top: '0px'},800).delay(3000).animate({top: '-500px'},800);
is there a more sensible way to do it?
I don’t get it. If there’s no need for the first
.animate(), when why do it? If you just need an extra400ms, then add it to the first.delay().Example: http://jsfiddle.net/LFt4k/
You don’t need an initial
.animate()to start a queue. The.delay()method will use the default"fx"queue.EDIT:
The issue you may be having is that if
#top-messagedoesn’t have an initial value fortop, it will be reported asautoin some browsers. This value is not useful for animations.To solve this, either give
#top-messagean initial value in CSS:…or in javascript: