Skip to main content
Code Review

Return to Revisions

3 of 3
replaced http://stackoverflow.com/ with https://stackoverflow.com/

jQuery Delay slideDown using Queue

I have the task to create a function that adds some messages to the page and another to show them in last to first order with a jQuery slideDown() effect.

jsFiddle

jQuery("#input1").click(function()
{
 //Represents the first function to add the messages
 jQuery.each(["<div>1</div>", "<div>2</div>", "<div>3</div>"],
 function(index, item)
 {
 var jDiv =jQuery(item);
 jDiv.hide();
 jQuery(".parent").prepend(jDiv);
 });
 //represents the second function to show them.
 var jParent = jQuery(".parent");
 jParent.children().reverse().each(function()
 {
 var jThis= jQuery(this);
 jParent.queue( function()
 {
 jThis.slideDown(function()
 {
 jParent.dequeue();
 });
 
 });
 }); 
});

(reverse from this answer)

jQuery.fn.reverse = [].reverse;

This seems to be an awful bunch of code just to show them one after another. Is there any way to clean up/remove redundant code?

James Khoury
  • 3.2k
  • 1
  • 25
  • 51
default

AltStyle によって変換されたページ (->オリジナル) /