JavaScript - Onmousemove
I'm writing a JavaScript Equation Editor / Whiteboard App, and i seem to be having a problem with one line of JavaScipt Code....
The Equation Editor is hosted live he http://kevinjohnson.clanteam.com/JsE...ionEditor.html Code: var AddMathElement = "<img src='" + Object.id + ".PNG' id='" + CurrentEquation + Elements + "' class='MathElement' onMouseDown='MoveImage(this, event);'>"; I have used the DOM Inspector (i'm using firefox) to look at the onMouseDown= event code, and it should work.... However, when i try to drag a Math Element Image to a different location (after it has been added to the page by clicking on the Math Element Keyboard), it does nothing. I looked on the Error Console, and there is nothing there. I looked at the Node value in the DOM inspector, and it is as it should be. I have also tried changing and removing some double quotes and single quotes, as that has worked in the past on similar code snippets. Similar TutorialsWhen a user pushes their mouse down on a DOM element I want to allow them to move it, so I would like to setup an on mouse move function. The code i have is: Code: var newHeader = document.createElement("div"); newHeader.id = "header" + tabID; newHeader.className = "windowHeader"; newHeader.onmousedown = 'desktop.onmousemove = moveWindow('+tabID+');'; newHeader.onmouseup = 'desktop.onmousemove = null;'; newWindow.appendChild(newHeader); However it doesn't work hence why I'm here... Any help appreciated! Hi I am trying to make a function run if the mouse is moved over the document but when using the object onmousemove it seems to run the code even if the mouse is still over then document, how can I make it so if the mouse is over the document but isn't moving then don't run the code but once the mouse moves run the code? This is the code I made to handle the mouse move collections. Code: function onmove(func) { var oldonmove = document.onmousemove; if(typeof document.onmousemove != 'function') { document.onmousemove = func; } else { document.onmousemove = function() { oldonmove(); func(); }; } } And to use it you would do this. Code: <script type="text/javascript"> /* Alert A Message Everytime The User Moves Their Mouse */ onmove(function(){ alert('You Moved!'); }); </script> But with this code it runs even when the user doesn't move their mouse and the notification box pops up every second as the code seems to think a still mouse is a moving mouse. I was thinking about having a run once system but that would mean if the mouse moves it runs once and then if the mouse moves again the code will not run as it has already ran before. If anyone can help me please reply, Thank You. DJCMBear. Hello, I've been writting HTML since last friday and javascript since yesterday. And I'm stuck on my first project. My functions for mouse_move / up / down all control the movement of a box. So you can click a box and move it anyway. It then snaps to an invisible grid. However there are multiple boxes on the screen so if you move it to a spot where another box already resides, then that box needs to swap places. This is what the mouse_over function tries to do. When I click the first box it stores the position of that box that was clicked. If I release the mouse button whilst hoovering over another box I want the other box to take the stored positions of the first box. However what I think is happening is the mouseover function is applying the new position to the box I'm moving, as I guess this is the first layer the mouse is over. Is there anyway I can reference the layer underneath using onmouseover. Sorry if this is jibberish. Thank you very much. Code: <script language="javascript"> var x; var y; var org_top; var org_left; var diff_org_top; var diff_org_left; var element; var element2; var being_dragged = false; var swap = false; function mouse_over(ele_name2) { if (swap = true) { element2 = ele_name2; document.getElementById(element2).style.top = org_top; document.getElementById(element2).style.left = org_left; swap = false; element2 = null } } function mouse_move(event) { x=event.pageX; y=event.pageY; if(being_dragged = true) { document.getElementById(element).style.top = y-diff_org_top +'px'; document.getElementById(element).style.left = x-diff_org_left +'px'; } } function mouse_down(ele_name) { being_dragged = true; swap = false element = ele_name; document.getElementById(element).style.cursor = 'move'; org_top = document.getElementById(element).style.top; org_left = document.getElementById(element).style.left; diff_org_top = y-org_top.substring(org_top.length-2,org_top); diff_org_left = x-org_left.substring(org_left.length-2,org_left); } function mouse_up() { being_dragged = false; document.getElementById(element).style.cursor = 'auto'; if (x < 317) { document.getElementById(element).style.left = Math.floor(x / 316 - 1) * 316 +'px'; } else { document.getElementById(element).style.left = 0+'px'; } element = null; swap = true; } </script> . SOURCE: Here Code: 1 document.onmousemove = mouseMove; 2 3 function mouseMove(ev){ 4 ev = ev || window.event; 5 var mousePos = mouseCoords(ev); 6 } 7 8 function mouseCoords(ev){ 9 if(ev.pageX || ev.pageY){ 10 return {x:ev.pageX, y:ev.pageY}; 11 } 12 return { 13 x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, 14 y:ev.clientY + document.body.scrollTop - document.body.clientTop 15 }; 16 } #1: How is it that "mouseMove" is assigned to "document.onmousemove" from right-to-left? What exactly is taking place here? #3: How can "mouseMove" be declared as a function afterwards? #3: I periodically see "e" being placed in functions. Is "ev" taking the place for "e"? If so is "ev" or "e" a global object? Where do they initially come from and how do they work? . |