Click to See Complete Forum and Search --> : How do I make an image shake??


nash
04-03-2003, 02:36 AM
I know it is possible to make an image shake when pointed by the mouse, but is it possible to have it to shake unless pointed by the mouse???

If it's possible, what's the code to do it???

Thanx

gil davis
04-03-2003, 06:03 AM
It would help to know how you are making it shake.

nash
04-03-2003, 06:53 AM
:o Yeah, you're right... here's the code tat makes the image to shake when pointed... :p

Between <HEAD> and </HEAD>:

<style>
.shakeimage {POSITION: relative}
</style>
<script>
/*
In header
*/
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>

In the body:

<a href="http://www.scriptsplus.com" target=_blank><img class=shakeimage onmouseout="stoprattle(this)" onmouseover="init(this);rattleimage()" src="video.gif" border=0 width=140 height=105></a>

I don't know how to change it so that it 'rattles' all the time and stops when pointed by the mouse...
Thanx for the help! :D

gil davis
04-03-2003, 07:19 AM
<body onload="init(document.images['x']);rattleimage()">
...
<img name="x" class="shakeimage" onmouseover="stoprattle(this)" onmouseout="stopit=0;rattleimage()" src="video.gif" border=0 width=140 height=105>

nash
04-03-2003, 07:29 AM
Kay, thanx, it works!!!:D