jQuery:setInterval [英] jQuery: setInterval
问题描述
我想在我的网站上制作幻灯片,但问题在于setInterval只能使用一次。它只加载我的文件一次结束然后停止。
继承人代码:
main.html
< img src =images / ex / full.jpgwidth =800height =377alt =>
< script>
$(document).ready(function(){
var refreshId = setInterval(function(){
$('#center')。load('images / gallery / best / rotate .php');
},5000);
});
< / script>
rotate.php
< img src =images / gallery / best / random.php?。<?php echo rand(0,1000)?> ;.width =800height =377 alt =>
random.php包含从选定文件夹加载随机图像的代码,效果很好。
忘了提及,我也收到了lightbox的脚本。也许他们不一起工作?
头:
< ; meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< script type =text / javascriptsrc =vendors / jquery / jquery-1.4.4.min.js>< / script>
< script type =text / javascriptsrc =vendors / js / prototype.js>< / script>
< script type =text / javascriptsrc =vendors / js / scriptaculous.js?load = effects,builder>< / script>
< script type =text / javascriptsrc =vendors / js / lightbox.js>< / script>
< link rel =stylesheethref =styles / style.csstype =text / css/>
< link rel =stylesheethref =styles / lightbox.csstype =text / css/>
谢谢。
<脚本>
$(document).ready(function(){
var refreshId = setInterval(function(){
var r =(-0.5)+(Math.random()*(1000.99) );
$('#center')。load('images / gallery / best / random.php?'+ r);
},5000);
});
< / script>
如何?
-
编辑
对不起,我的意思是你应该随机化setInterval函数中的照片。如上所述。而不是rotate.php;只需加载random.php。
I want to make a slideshow on my site, but the problem is that the setInterval works only one time. It loads my file only one time end then stops.
Heres the code: main.html
<img src="images/ex/full.jpg" width="800" height="377" alt="">
<script>
$(document).ready(function(){
var refreshId = setInterval(function(){
$('#center').load('images/gallery/best/rotate.php');
}, 5000);
});
</script>
rotate.php
<img src="images/gallery/best/random.php?".<?php echo rand(0,1000) ?>."" width="800" height="377" alt="">
random.php contains a code which loads random image from selected folder, it works good.
Forgot to mention, I got lightbox scripts included too. Maybe they don't work together?
Head:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="vendors/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="vendors/js/prototype.js"></script>
<script type="text/javascript" src="vendors/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="vendors/js/lightbox.js"></script>
<link rel="stylesheet" href="styles/style.css" type="text/css" />
<link rel="stylesheet" href="styles/lightbox.css" type="text/css" />
Thanks.
<script>
$(document).ready(function(){
var refreshId = setInterval(function(){
var r = (-0.5)+(Math.random()*(1000.99));
$('#center').load('images/gallery/best/random.php?'+r);
}, 5000);
});
</script>
How about that?
--
Edit
Sorry, I meant that you should just randomize the photos in the setInterval function. As illustrated above. Instead of rotate.php; just load random.php.
这篇关于jQuery:setInterval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!