/    Sign up×
Community /Pin to ProfileBookmark

How do I check for onmousemove and onMouseDown together?

Hi, A simple question which I’m stuck with. I am trying to alter a script which currently calls some code if the mouse is moved over and image.
I wish to alter this so that it only calls the code if the mouse is pressed down [U]at the same time[/U] as the mouse being moved. I thought I could just add in the extra test but I’m not quite sure how I do this.

I have tried

[CODE]crossmain.onmousemove[COLOR=Teal] && onmousedown[/COLOR]=function(e)[/CODE]

thinking that that would only call the code if both requirements were met but this does not work.

Help please :rolleyes:

Thanks
Andy

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@netbuddyJun 11.2006 — You wouldnt be able to use 2 events at the same time, which ever event triggers first will call any function that it has had set to it...
Copy linkTweet thisAlerts:
@vwphillipsJun 11.2006 — var move;

onmousedown move=true;

onmouseup move=false;

onmousemove if (move){ doit }

leave you to do the coding
Copy linkTweet thisAlerts:
@felgallJun 11.2006 — Moving the mouse while the mouse button is held down is a drag event.

ondragstart

ondrag

ondragend
Copy linkTweet thisAlerts:
@mrhooJun 12.2006 — Use the mousedown from the image to set the mousemove function,

remove it on mouseup.
Copy linkTweet thisAlerts:
@centroauthorJun 12.2006 — var move;

onmousedown move=true;

onmouseup move=false;

onmousemove if (move){ doit }

leave you to do the coding[/QUOTE]


Thanks for looking at this Vic, So you are doing a two stage test. Only if the mouse is pressed does it proceed to the mousemove test.

I have tried to impliment your idea but I guess I am a bit new to Javascript.

the original code is like this...

[CODE]crossmain.onmouseout=function(e){stopmotion(e)}[/CODE]

How exactly would I use YOUR code in the above. I'm having problems with the exact syntax. :mad:

Thanks

Andy
Copy linkTweet thisAlerts:
@vwphillipsJun 12.2006 — [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

// object.onmousedown=function(event) { zxcMseDown(event,this);}


function zxcMse(event){
if(!event) var event=window.event;
if (document.all){ return [event.clientX+zxcDocS()[0],event.clientY+zxcDocS()[1]]; }
else {return [event.pageX,event.pageY]; }
}

function zxcDocS(){
var zxcsx,zxcsy;
if (!document.body.scrollTop){ zxcsx=document.documentElement.scrollLeft; zxcsy=document.documentElement.scrollTop; }
else { zxcsx=document.body.scrollLeft; zxcsy=document.body.scrollTop; }
return [zxcsx,zxcsy]
}



function zxcEventAdd(zxco,zxct,zxcf) {
if ( zxco.addEventListener ){ zxco.addEventListener(zxct, function(e){ zxco[zxcf](e);}, false); }
else if ( zxco.attachEvent ){ zxco.attachEvent('on'+zxct,function(e){ zxco[zxcf](e); }); }
else {
var zxcPrev=zxco["on" + zxct];
if (zxcPrev){ zxco['on'+zxct]=function(e){ zxcPrev(e); zxco[zxcf](e); }; }
else { zxco['on'+zxct]=zxco[zxcf]; }
}
}


var zxcEvt=0;

function zxcAddEvt(zxco,zxcfun,zxcevt){
if (zxco['zxc'+zxcfun+zxcevt]){ return; }
zxco['zxcaddEvt'+zxcEvt]=window[zxcfun];
zxco['zxc'+zxcfun+zxcevt]=true;
zxcEventAdd(zxco,zxcevt,'zxcaddEvt'+zxcEvt);
zxcEvt++;
}

zxcAddEvt(document,'zxcMseUpDown','mousedown')
zxcAddEvt(document,'zxcMseUpDown','mouseup')
zxcAddEvt(document,'zxcMseMove','mousemove')

var zxcD;

function zxcMseMove(zxcevt){
if (zxcD){
document.Show.Show0.value=zxcMse(zxcevt);
}
else {
document.Show.Show0.value='Mouse is Up';
}
}

function zxcMseUpDown(zxcevt){
zxcD=false;
if (zxcevt.type=='mousedown'){ zxcD=true; }
}

//-->
</script>
</head>

<body>

<script> vic=0; </script>
<form name=Show id=Show style="position:absolute;visibility:visible;top:450px;left:0px;" >
<input size=100 name=Show0 >
<input size=10 name=Show1 >
<input size=10 name=Show2 >
<input size=10 name=Show3 >
<input size=10 name=Show4 >
<input size=10 name=Show5 >
<input size=10 name=Show6 >
<input size=10 name=Show7 >
<input size=10 name=Show8 >
<input size=10 name=Show9 >
</form>
</body>

</html>[/CODE]
×

Success!

Help @centro 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 5.21,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...