PDA

View Full Version : Moving images on mouseover?



speedytina
07-29-2005, 06:29 AM
Hi:
I'm a java script newbie and this my first post. Would anyone know where I might find a script that could do the following? I want to make an image move on mouseover. I want to be able to make the image move to the right one space equivalent to its size . Then when I mouseover its new location I want the image to move back to its origional position. I want this back and forth positioning to be repeatable. I want the image to move instantly as soon as the mouse touches it.
I have seen this effect somewhere before. I'm hoping someone can steer me in the right direction.
This is a great forum.
Thanks

Twey
07-29-2005, 09:30 AM
<script type="text/javascript">
function switchPos(obj) {
if(obj.style.left != obj.style.width) {
obj.style.left = obj.style.width;
} else {
obj.style.left = '0pt';
}
}
</script>

<img
src="image.jpg"
style="position:relative; left:0; width:100px;"
onmouseover="switchPos(this);"
/>

Change the values in green to those appropriate for your image. You don't need to copy the script for multiple images, just the <img> tag.

speedytina
07-29-2005, 02:52 PM
Twey;

Thanks a million. Works like a charm. Made my day.

speedytina