Variable Visions

Articles jQuery Javascript-setInterval-with-random-content-loaded-with-AJAX


tutorials - jQuery and Web-Development.

Javascript setInterval with random content loaded with AJAX

Published Thu. Sep. 06, 2012


The below function was written to display six random articles by fading in and out

/* EVERY FIVE SECONDS THE PHP FILE WITH ARRAY WILL LOAD VIA AJAX INTO THE CONTAINER ID AFTER THE FIRST ARRAY IS FADED OUT QUICKLY AND THEN DELAY THE LOAD BY ONE SECOND AND FADE IN THE NEXT IN ONE SECOND */

window.setInterval(function(){   
            jQuery('#container').fadeOut(100).load('/file.php?limit=6').delay(1000).fadeIn(1000);
},5000)

 

You can also slideUp, slideDown, etc.


window.setInterval(function(){   
            jQuery('#container').slideUp(100).load('/file.php?limit=6').delay(1000).slideDown(1000);
},5000)


Tag(s): window.setInterval, .delay, .fadeIn, .fadeOut