var number = 3//总图片数量
var num = number-1
var speed = 3000//间隔时间
function amouseover(){
ismouseover = true
}
function amouseout(){
ismouseover = false
}
.
.
.
function imgSwitch(){
if(!ismouseover){
var imgNow = document.getElementById("switch")
var iNow = Math.floor(Math.random()*num)
imgNow.src = imgDyn[iNow][0]
imgNow.parentNode.href = imgDyn[iNow][1]
imgDyn.splice(iNow,1)
if(num>0){
num = num-1
}else{
num = number -1
imgInit()
}
}
setTimeout(imgSwitch,speed)
}
.
.
.
<a onmouseover='amouseover()' onmouseout='amouseout' href="#" target="_blank"><img id="switch" src="" width="100%"></a>
设置图片的父元素为相对定位;
设置图片为绝对定位;
假设图片宽为w,高为h,放大后的宽为2w,高为2h,则计算其位置如下:
left:-(2w-w)/2,
top:-(2h-h)/2