This article illustrates the method of JS implementation of the mouse trigger image jitter effect. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
<title> Mouse trigger image jitter effect </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>
<body bgcolor= "#F7F7F7" >
<p align= "center" >
<br>
Mouse move up to see the effect! </p>
</body>
I hope this article will help you with your JavaScript programming.