javascript - Load List Items dynamically with JQuery - Stack Overflow
I'd like to structure my JQuery to fade in each individual item at a time. Here's an example of the behavior, and here's the JQuery I have so far:
$('li').css('display', 'none') .delay(1000).fadeIn(800)
I'd like to structure my JQuery to fade in each individual item at a time. Here's an example of the behavior, and here's the JQuery I have so far:
$('li').css('display', 'none') .delay(1000).fadeIn(800)
Share
Improve this question
edited Feb 8, 2011 at 12:52
Bill the Lizard
406k212 gold badges574 silver badges892 bronze badges
asked Feb 8, 2011 at 11:34
satsat
1,0093 gold badges19 silver badges41 bronze badges
0
6 Answers
Reset to default 3This probably not the best solution but it should work:
$('li').each(function(i){
var el = this;
setTimeout(function(){
$(el).fadeIn(800);
},800*i)
});
Just for fun, a recursive version:
function animateLi(i){
$('li').eq(i).fadeIn(800);
if ($('li').eq(i+1).length>0)
{
setTimeout(function(){animateLi(i+1)},800);
}
}
animateLi(0);
Maybe something like this:
var delay = 500, t = 0;
$("li").css('display', 'none').each(function(){
t += delay;
var $li = $(this);
setTimeout(function(){
$li.fadeIn();
},t);
});
Loop through the li, and use setTimeout to queue the animation for that li.
$('li').each(function () {
var li = this;
animateLi = function () {
li.fadeIn(800);
}
setTimeout(animateLi, timeout);
timeout += 100;
});
A slight variation on Ivans method
$(function() {
$('ul li:hidden').each(function(idx) {
setTimeout(function(el) {
el.fadeIn();
}, idx* 1000, $(this));
});
});
And a recursive function using fadeIn callback function instead of setTimeout
function DisplayOneByOne(){
$('ul li:hidden:first').fadeIn('2000', DisplayOneByOne);
}
Here is how you do it:
var delay = 200, t = 0;
$("li").css('display', 'none').each(function(){
t += delay;
var $li = $(this);
setTimeout(function(){
$li.fadeIn(1900);
},t);
});
There is another way to fade in elements after each other:
$.fn.fadeInNext = function(delay) {
return $(this).fadeIn(delay,function() {
$(this).next().fadeInNext();
});
};
$('li').hide().first().fadeInNext(1000);
最新文章
- 成本高、厂商疑 微软Surface面临十大风险
- 奇虎诉腾讯索赔1.5亿创天价 双方股价昨齐上涨
- 有事请烧纸!清明祭奠已死的平板电脑
- python - tensorflow-gpu installation failed in colab - Stack Overflow
- python - Chromadb: Why do results of collection.query() and collection.get() differ? - Stack Overflow
- ST_CONTAINS() giving FALSE even if Point lies within polygon. google-bigquery - Stack Overflow
- python - Plotting a list of integer 3d values into Axes3d.voxels - Stack Overflow
- bitcoin - Problem with sign PSBT.Error sign transaction - Stack Overflow
- python - Can't run pytest with a `FileNotFoundError: [Errno 2] No such file or directory: 'tmppip-build-env-3fag
- c# - IdentityServer4 and returning an error in response - Stack Overflow
- darkmode - Eclipse IDE - Dark Mode: When "Link With Editor" is enabled in project explorer the selected file&a
- flutter - Connect user to stripe connect to allow him receiving money - Stack Overflow
- indexing - mysql 5.7 why this sql not using index_merge,it using a full table scan - Stack Overflow
- javascript - onPointerOver and onPointerOut detect all child elements - Stack Overflow
- angularjs - how to display a pdf in angular? - Stack Overflow
- reactjs - Google Books API setOnLoadCallback works only after page reload - Stack Overflow
- lean - Lean4 good way to solve `imports are out of date` - Stack Overflow