js鼠標(biāo)滑過圖片震動(dòng)特效的方法

字號(hào):


    這篇文章主要介紹了js鼠標(biāo)滑過圖片震動(dòng)特效的方法,涉及onMouseOver事件及圖片操作的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    本文實(shí)例講述了js鼠標(biāo)滑過圖片震動(dòng)特效的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
    代碼如下:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>鼠標(biāo)滑過 圖片震動(dòng)效果</title>
    <STYLE>.shakeimage {
    POSITION: relative
    }
    </STYLE>
    </head>
    <body>
    <SCRIPT language=JavaScript1.2>
    <!--
    var rector=3
    var stopit=0
    var a=1
    function init(which){
    stopit=0
    shake=which
    shake.style.left=0
    shake.style.top=0
    }
    function rattleimage(){
    if ((!document.all&&!document.getElementById)||stopit==1)
    return
    if (a==1){
    shake.style.top=parseInt(shake.style.top)+rector
    }
    else if (a==2){
    shake.style.left=parseInt(shake.style.left)+rector
    }
    else if (a==3){
    shake.style.top=parseInt(shake.style.top)-rector
    }
    else{
    shake.style.left=parseInt(shake.style.left)-rector
    }
    if (a<4)
    a++
    else
    a=1
    setTimeout("rattleimage()",50)
    }
    function stoprattle(which){
    stopit=1
    which.style.left=0
    which.style.top=0
    }
    //-->
    </SCRIPT>
    <img onMouseOver="init(this);rattleimage()" onMouseOut="stoprattle(this)" src="/images/csrcode.ico"/>
    <img onmouseover="init(this);rattleimage()" onmouseout="stoprattle(this)" src="/images/changshi.ico"/>
    <img onmouseover="init(this);rattleimage()" onmouseout="stoprattle(this)" src="/images/links.ico"/>
    鼠標(biāo)滑過圖片預(yù)覽效果。
    </body>
    </html>
    希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。