首页 > 代码库 > js图片轮播
js图片轮播
html部分
<a href="" id="pta"><div id="picture" class="pt"></div></a>a标签包裹着div,背景图片作为链接
script部分
var n=-1;//n作为全局变量放在外面,否则每次刷新n的值都是-1
function pt(){
var tp=new Array(‘url(../bank/picture/1111.jpg)‘,‘url(../bank/picture/2222.jpg)‘,‘url(../bank/picture/3333.jpg)‘,‘url(../bank/picture/4444.jpg)‘)
var adiv=new Array(‘http://www.bankofchina.com/pbservice/bi3/201701/t20170124_8524721.html‘,‘http://www.bankofchina.com/pbservice/pb7/‘,‘http://www.bankofchina.com/pbservice/pb8/‘,‘http://www.bankofchina.com/cbservice/cb11/‘)
var picture=document.getElementById(‘picture‘)
var pta=document.getElementById(‘pta‘)
n+=1
e=n%tp.length;
pta.setAttribute(‘href‘,adiv[e])
picture.style.background=tp[e]
setTimeout(‘pt()‘,3000)
}
pt()
js图片轮播