Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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 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?

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?

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?

deleted 14 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

JQuery jQuery Delay slideDown using Queue

So 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()slideDown() effect.

So i came up with: (jsfiddlejsFiddle )

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. AnywayIs there any way to clean up/remove redundant code?

JQuery Delay slideDown using Queue

So 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.

So i came up with: (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. Anyway to clean up/remove redundant code?

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?

Source Link
James Khoury
  • 3.2k
  • 1
  • 25
  • 51

JQuery Delay slideDown using Queue

So 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.

So i came up with: (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. Anyway to clean up/remove redundant code?

default

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