Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onmousedown and onmousemove

Status
Not open for further replies.

victorsk

Programmer
Jul 26, 2005
21
CA
Hello,

I am new to JavaScript and kind of confused as to why my onmousedown together with onmousemove condition is not being implemented. Here is what I have:
1) SVG code calling JavaScript function

<g id="0" style="display:inline;fill-rule:evenodd">
<desc>0</desc>
<image id="image_url0" xlink:href="draw_svg.svg" width="1000" height="1000" onmousedown="doZoom(evt, 1);" onmousemove="doZoom(evt, 1);" onmouseup="doZoom(evt, 1);" />
</g>

2) JavaScript function:

function doZoom(evt, current) {
//THIS SHOULD WORK
if (evt.type == "mousedown" && evt.type == "mousemove" ) {
var SVGDoc = evt.getTarget().getOwnerDocument();
var SVGChild = SVGDoc.getElementById("maps");
var svgobj = SVGChild.getElementById("0");
svgobj.getStyle().setProperty('display', 'none');
}
}
But the code works only if I say: 'if (evt.type == "mousedown") without "mousemove" . Please note, that I am calling my function onmousemove event also so it should register. I will very much appreciate if somebody could tell me why 'mousemove' AND 'mousedown' both don't work in my 'If' statement.

Thank you,
Victor.
 
Would a single event (evt) be capable of having two different types? Maybe you mean or rather than and.
>[tt]if (evt.type == "mousedown" && evt.type == "mousemove" ) {
if (evt.type == "mousedown" [red]||[/red] evt.type == "mousemove" ) {[/tt]
 
Hi,

Thanks for replying. Unfortunately this is a drag action so the image must be dragged when both mouse pressed and moved.

Thanks,
Victor.
 
Hi All,

I found the solution. It is to use a global variable and assign a value to it when mouse is pressed and use that variable in the 'if' condition instead of 'evt.type'. I used a local variable for this purpose but it looks like only global works. Why? Beats me.

Thanks,
Victor.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top