I am using below snippet to load a page content in #load div
var auto_refresh = setInterval(function() {
$('#load').load('load.php?_=' +Math.random()).fadeIn(3000);
}, 10000); // refresh every 10000 milliseconds
It loads pages after each 10 seconds.
Now come to the point what i want. I have five pages.
I need to set loop that autoload pages in every 2 minutes. And so on and at the end it starts from the beginning.
please help me to make this give me some ideas.
Thanks in advance
Try this:
var i = 0;
var loadPage = setInterval(function() {
$('#load').load('page'+(i++) + '.php').hide().fadeIn(3000);
}, 2000); //---------^^^^^^^^^^^^^^^^^^^----page with number and extension
if(i >= 5){
clearInterval(loadPage);
}
You haven't told me the format for your pages so I'm assuming you can use numbers to simply count up.
var seed = 0;
var lastPageNumber = 10;
setInterval(function() {
$('#load').load('load.php?page=' + seed + '_=' + Math.random()).fadeIn(3000);
if(seed === lastPageNumber) {
seed = 0;
}
seed++;
}, 120000); // refresh every 120000 milliseconds (120 seconds -> 2 minutes)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.