/    Sign up×
Community /Pin to ProfileBookmark

Mouseover event while mouse is down

Hello,
I am trying to have the mouseover event continue the entire time the mouse is over the hyperlink.
right now when the mouseover event is triggered, it tells an object to move 5 pixels, but it happens only once.
My goal is to have the object move 5 pixels at 0.5 second intervals while the mouse is over the hyperlink. It should not stop untill the mouse moves from the hyperlink.
Is there anyway to loop the mouseover event (or any event) until told to stop?

Heres an example of the code i have so far:

<html>
<head>
<script>

function funMovDis(obj, x, y){
obj = document.getElementById(obj);
obj.style.left=parseInt(obj.style.left)+x+”px”;
obj.style.top=parseInt(obj.style.top)+y+”px”;
}

</script>
</head>
<body>
<img src =”circle.gif” id = ‘obj2’ style=”position: absolute; left: 150px; top: 280px”>
<a href=”#” onmouseover=”funMovDis(‘obj2’, 0, -5);”>UP</a>
<a href=”#” onmouseover=”funMovDis(‘obj2’, 0, 5);”>DOWN</a>
<a href=”#” onmouseover=”funMovDis(‘obj2’, -5, 0);”>LEFT</a>
<a href=”#” onmouseover=”funMovDis(‘obj2’, 5, 0);”>RIGHT</a>
</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@wasim___drushtiJun 14.2006 — :eek: I struggled for this, finally solved it.

have a look

[CODE]
<html>
<head>
<script>

function funMovDis(obj, x, y){

obj = document.getElementById(obj);
obj.style.left=parseInt(obj.style.left)+x+"px";
obj.style.top=parseInt(obj.style.top)+y+"px";

}


var t;
function moveLeft()
{
t = setTimeout('moveLeft()', 50);
funMovDis('obj2', -5, 0);
}

function moveRight()
{
t = setTimeout('moveRight()', 50);
funMovDis('obj2', 5, 0);
}

function moveUp()
{
t = setTimeout('moveUp()', 50);
funMovDis('obj2', 0, -5);
}

function moveDown()
{
t = setTimeout('moveDown()', 50);
funMovDis('obj2', 0, 5);
}


function moveStop()
{
clearInterval(t);

}

</script>
</head>
<body>
<img src ="circle.gif" id = 'obj2' style="position: absolute; left: 150px; top: 280px">
<a href="#" onmouseover="moveUp();" onmouseout="moveStop();">UP</a>
<a href="#" onmouseover="moveDown();" onmouseout="moveStop();">DOWN</a>
<a href="#" onmouseover="moveLeft();" onmouseout="moveStop();">LEFT</a>
<a href="#" onmouseover="moveRight();" onmouseout="moveStop();">RIGHT</a>
</body>
</html>

[/CODE]


Don't forget to reply me and Post your view :
Copy linkTweet thisAlerts:
@gilooshauthorJun 14.2006 — Thanks! It Works Perfectly! ?
×

Success!

Help @giloosh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...