如何迭代数组中的 url,并在 iframe 中显示每个 url?
此代码的目的是循环遍历 URL 并将最新的 URL 插入 iframe 中。下面,我使用jquery的倒计时插件。
<?php
$count=0;
$urls[]="http://www.techcrunch.com";
$urls[]="http://www.livingsocial.com";
$urls[]="http://www.guardian.co.uk";
$urls[]="http://www.google.com";
$urls[]="http://www.rightmove.com";
$urls[]="http://www.godaddy.co.uk";
foreach ($urls as $count){
?>
<script type="text/javascript">
$(function start() {
var changetimer = new Date();
changetimer.setSeconds(changetimer.getSeconds() + 10.5);
$('#defaultCountdown').countdown({until: changetimer, onExpiry: liftOff});
$('#year').text(changetimer.getFullYear());
});
function liftOff() {
document.getElementById("mainview").src = '<?php echo($count); ?>';
}
</script>
<?php } ?>
</head>
下面是在 body 标签中。
<iframe id="mainview" width="800" height="400" src="http://www.holidays.com">
</iframe>
这里的问题是这段代码跳过了 url 列表,速度太快,您只能看到第一个和最后一个 url。到目前为止,中间的网址是不可见的,并且倒计时器仅出现一次。我正在使用 jquery 倒计时插件。
如何使其慢下来并在进入下一个之前单独显示倒计时的每次迭代?非常感谢。
The purpose of this code is to loop through the urls and insert the latest one into the iframe. Below, I am using jquery's countdown plugin.
<?php
$count=0;
$urls[]="http://www.techcrunch.com";
$urls[]="http://www.livingsocial.com";
$urls[]="http://www.guardian.co.uk";
$urls[]="http://www.google.com";
$urls[]="http://www.rightmove.com";
$urls[]="http://www.godaddy.co.uk";
foreach ($urls as $count){
?>
<script type="text/javascript">
$(function start() {
var changetimer = new Date();
changetimer.setSeconds(changetimer.getSeconds() + 10.5);
$('#defaultCountdown').countdown({until: changetimer, onExpiry: liftOff});
$('#year').text(changetimer.getFullYear());
});
function liftOff() {
document.getElementById("mainview").src = '<?php echo($count); ?>';
}
</script>
<?php } ?>
</head>
the below is in the body tag
<iframe id="mainview" width="800" height="400" src="http://www.holidays.com">
</iframe>
The problem here is this code skips through the list of urls so quickly you only see the first one, and the last url. The urls inbetween are so far invisible and the countdown timer only appears once. I am using the jquery countdown plugin.
How do I make this slow down and show each iteration of the count down individually before moving to the next? thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您将所有计时器设置为完全相同的时间。您需要将它们设置为不同的时间。与其为每个添加 10.5 秒,不如添加“10.5*数组索引”,以便每个等待比前一个等待的时间长一点。
The problem is that you are setting all of your timers to go off at exactly the same time. You need to set them for different times. Instead of adding 10.5 seconds for each one, maybe add "10.5*the array index" so that each one waits a little longer than the previous.
这样做:
Do it like this: