0

Trying to use JQuery to make several elements, each in their own DIV, phase in with their own "delay" and "fadeIn" values. I have it working in This Fiddle, but is this the most efficient way to go? In the live site, I will pass a random number via PHP for the delay and fadeIn values.

Here is the JQuery:

$(".fade1").hide(0).delay(500).fadeIn(500); $(".fade2").hide(0).delay(800).fadeIn(1750); $(".fade3").hide(0).delay(1000).fadeIn(3500); $(".fade4").hide(0).delay(1500).fadeIn(5000); 
1
  • It'd be inefficient if you have a lot of elements in the parent container .fade_container. How about a loop that goes through the children of that? You can then bind .fadeIn to each of those with an increasing interval on both .delay and .fadein Commented Nov 21, 2014 at 15:51

1 Answer 1

1

You can write a tiny jQuery plugin script like below:

$.fn.hideNFadeIn = function (opts) { var options = opts; this.each(function (i) { $(this).hide(0).delay(options.delay[i]).fadeIn(options.fadeIn[i]); }); }; $('.fade1, .fade2, .fade3, .fade4').hideNFadeIn({ delay: [500, 800, 1000, 1500], fadeIn: [500, 1750, 3500, 5000] }); 

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Nice idea! I have updated my original Fiddle with this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.