js實現(xiàn)鼠標(biāo)觸發(fā)圖片抖動效果的方法
更新時間:2015年02月27日 09:28:30 作者:代碼家園
這篇文章主要介紹了js實現(xiàn)鼠標(biāo)觸發(fā)圖片抖動效果的方法,通過定時器定時遞歸調(diào)用rattleimage函數(shù)實現(xiàn)抖動效果,非常實用,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了js實現(xiàn)鼠標(biāo)觸發(fā)圖片抖動效果的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
<html>
<head>
<title>鼠標(biāo)觸發(fā)圖片抖動效果</title>
<style>
.shakeimage{
position:relative
}
</style>
<script language="JavaScript1.2">
//configure shake degree (where larger # equals greater shake)
var rector=3
///////DONE EDITTING///////////
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>
</head>
<body bgcolor="#F7F7F7">
<p align="center">
<img src=/images/skinslogo.gif class="shakeimage" onMouseover="init(this);rattleimage()" onMouseout="stoprattle(this)">
<br>
鼠標(biāo)移動上來看效果!</p>
</body>
</html>
<head>
<title>鼠標(biāo)觸發(fā)圖片抖動效果</title>
<style>
.shakeimage{
position:relative
}
</style>
<script language="JavaScript1.2">
//configure shake degree (where larger # equals greater shake)
var rector=3
///////DONE EDITTING///////////
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>
</head>
<body bgcolor="#F7F7F7">
<p align="center">
<img src=/images/skinslogo.gif class="shakeimage" onMouseover="init(this);rattleimage()" onMouseout="stoprattle(this)">
<br>
鼠標(biāo)移動上來看效果!</p>
</body>
</html>
希望本文所述對大家的javascript程序設(shè)計有所幫助。
相關(guān)文章
javascript smipleChart 簡單圖標(biāo)類
支持 線性圖 區(qū)域圖 柱狀圖 餅圖 支持多瀏覽器 用到的是svg vml 之后加上 多層餅圖 分段圖 和組合圖2011-01-01js 數(shù)字、字符串、布爾值的轉(zhuǎn)換方法(必看)
下面小編就為大家?guī)硪黄猨s 數(shù)字、字符串、布爾值的轉(zhuǎn)換方法(必看)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04JavaScript數(shù)據(jù)庫TaffyDB用法實例分析
這篇文章主要介紹了JavaScript數(shù)據(jù)庫TaffyDB用法,實例分析了TaffyDB數(shù)據(jù)庫的定義、查詢、更新、刪除等操作的相關(guān)使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07js下通過prototype擴(kuò)展實現(xiàn)indexOf的代碼
這里使用js prototype擴(kuò)展實現(xiàn)的indexOf的實現(xiàn)代碼,跟js自帶的方法,差不多。2010-12-12