Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to animate jquery load()

hello im using this code to load content from another php file.

$(document).ready(function(){
           setInterval(function(){
                               $('.live-stream ul').each(function(){
                                    $(this).load('tx.php');
                        });
                }, 1000);

        });  

this works correctly but i want script to fadeIn each "li" when a new record added, anyone?

the thing i want to do is something like facebook's live user action feed that on the right top of facebook home

like image 451
Ali Demirci Avatar asked Dec 13 '11 17:12

Ali Demirci


People also ask

How do you animate in jQuery?

The jQuery animate() method is used to create custom animations. Syntax: $(selector).animate({params},speed,callback); The required params parameter defines the CSS properties to be animated.

How can I create a please wait loading animation using jQuery?

$body = $("body"); $(document). on({ ajaxStart: function() { $body. addClass("loading"); }, ajaxStop: function() { $body. removeClass("loading"); } });

Is jQuery good for animation?

The jQuery library provides several techniques for adding animation to a web page. These include simple, standard animations that are frequently used, and the ability to craft sophisticated custom effects.

Is jQuery slower for animations?

jQuery can be several times slower than CSS when talking about animations. CSS animations and transitions have the advantage of being hardware accelerated by the GPU, which is really good in moving pixels.


2 Answers

You have to hide it first.

$(this).hide().load("tx.php").fadeIn('500');
like image 80
Andri Avatar answered Nov 07 '22 19:11

Andri


Try something like this:

$(document).ready(function(){
     setInterval(function(){
        $('.live-stream ul').each(function(){
           $(this).hide().load('tx.php').fadeIn('500');
        });
     }, 1000);

});  

Note the use of fadeIn() and hide()... You don't need hide if you already have the <li>'s hidden.

like image 27
sirmdawg Avatar answered Nov 07 '22 20:11

sirmdawg