js图片跳动

JavaScript014

js图片跳动,第1张

JS文件:

 function show(){

 var imgid=document.getElementById("imgid")

if(imgid.style.visibility == "visible")

  imgid.style.visibility = "hidden"

else

  imgid.style.visibility = "visible"

 

  setTimeout('show()',300)

 }

HTML:

<img id="imgid" style="visibility:visible" src="1.jpg" />

<button onclick="show()">按下图片会闪动</button>

不知道你是不是这个意思 发现有点没读懂你想要的东西

JS的 HTML DOM 事件

给你个鼠标移动到图片的事件例子:

<!DOCTYPE html>

<html>

<body>

<div

onmouseover="mOver(this)"

onmouseout="mOut(this)"

style="background-color:#D94A38width:200pxheight:50pxpadding-top:25pxtext-align:center">

Mouse Over Me

</div>

<script>

function mOver(obj)

{

obj.innerHTML="鼠标移到DIV"

}

function mOut(obj)

{

obj.innerHTML="鼠标离开DIV"

}

</script>

</body>

</html>

上面只是设置了移到改变文本 ,你可以利用本事件设置鼠标移到和离开时目标div的CSS实现效果!或者追问详细说明要什么样的效果,我帮你做!

已修改,复制粘贴即可

<html>

<head>

<meta charset="utf-8" />

<title>cainiao</title>

<script type="text/javascript">

var speed = 0

    var timer = null

    var oImg = null

    var oPa = 0.5

    window.onload = function ()

    {

    oImg = document.getElementById ("img7")

    oImg.onmouseover = function ()

    {

    toMove (1)

    }

    oImg.onmouseout = function ()

    {

    toMove (0.5)

    }

    }

    

    function toMove (i)

    {

    if (!!timer)

    {

    clearInterval (timer)

    timer = null

    }

    timer = setInterval (function ()

    {

    if (i > oPa)

    {

    speed = 0.1

    }

    else if (i < oPa)

    {

    speed = -0.1

    }

    if (oPa == i)

    {

    clearInterval (timer)

    timer = null

    }

    else

    {

    oPa = oPa + speed

    }

    if (!window.ActiveXObject)

    {

    oImg.style.opacity = oPa

    }

    else

    {

    oImg.style.filter = 'alpha(opacity=' + parseFloat (oPa) * 100 + ')'

    }

    }, 60)

    }

</script>

</head>

<body>

<img id="img7" src="images/scifier.jpg" width="180px"

style="filter:alpha(opacity=50)opacity: 0.5" />

</body>

</html>