我试图复制像这样的横幅广告,但我需要它通过三个动画gif循环。
下面是我在这里修改的示例代码:
// randomization
var index = Math.floor(Math.random() * 3);
var images = new Array("<div class='ad'><a href = 'https://www.poundstopocket.co.uk/buildapp' target='_blank'>
<img src='https://www.poundstopocket.co.uk/pound-place/wp-content/themes/shaken-grid-premium/images/1.gif' alt='Visit Computer Hope'></a></div>",
"<div class='ad'><a href = 'https://www.poundstopocket.co.uk/straightforwardapp' target='_blank'><img src='https://www.poundstopocket.co.uk/pound-place/wp-content/themes/shaken-grid-premium/images/2.gif' alt='Computer History'></a></div>",
"<div class='ad'><a href = 'https://www.poundstopocket.co.uk/nohiddenfeesapp' target='_blank'><img src='https://www.poundstopocket.co.uk/pound-place/wp-content/themes/shaken-grid-premium/images/3.gif' alt='Visit Computer Hope'></a></div>")
// loop
setInterval(function() {
$('.ad').html(images[index])
if(index == 2){
index = 0;
}else{
index++;
}
}, 5000); 其中包括大部分jscript和来自网站的图像。
这个循环不像我需要的那样工作,为了我自己的目的,我需要循环重置,并在0,1或2重新开始,因为在随机化的初始脚本中,我想保留这一部分,但连续循环3,5或6秒gif。
发布于 2014-04-24 20:20:42
这样做要容易得多-首先随机化你的数组的顺序。
images.sort(function() { return Math.floor(Math.random() * 2); });然后
var ad = $('.ad'), next = 0;
setInterval(function() {
ad.html(images[next]);
next = images[next+1] ? next+1 : 0;
}, 5000);https://stackoverflow.com/questions/23268663
复制相似问题