JavaScript图片切换修改:鼠标悬停

JavaScript015

JavaScript图片切换修改:鼠标悬停,第1张

var ismouseover = false //控制是否换图 ---增加的

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>

<div

id="s">Show</div>

<div

id="h"

style="display:none">Hidden</div>

当鼠标进入

id

s

Div

显示下面本来隐藏的

Div。

当鼠标离开时

隐藏

<script>

var

show

=

document.getElementById('s')

var

hidden

=

document.getElementById('h')

show.onmouseover

=

function

()

{

hidden.style.display

=

"block"

}

show.onmouseleave

=

function

()

{

hidden.style.display

=

"none"

}

</script>