document.onmousemove not working quite right help?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Mayor

    #1

    document.onmousemove not working quite right help?

    Hi,
    I'm re phrasing and earlier question as the earlier question doesn't
    make to much sense. I using document.onmous emove to move a <div line on
    the screen. At the moment if I click and move the mouse over the image
    it doesn't move the line but if I click off the image and move the mouse
    the line moves like it's supposed to. Also if I click it off the image
    and move the mouse over the image it then works. Something on clicking
    the image is messing it up.

    Can someone please tell me why when I click off the image it works and
    when i click on the image and move it it doesn't. Here's my script so far.

    Help please as this has really got me stuck at the moment. The code
    works in NS6 and Mozilla.

    Thanks

    Anyone Know?

    Gary
    <HTML>
    <HEAD>
    </head>
    <body bgcolor="FFFFFF ">

    <img name="main" border="1" src="iecadaptor .jpg">

    <div id="top2" style="position :absolute; width:308px; height:1px;
    z-index:1; left: 29px; top: 23px; overflow: visible; visibility: hidden;
    background-color: black; layer-background-color: black; border: 1px none
    #000000"></div>

    <script language="javas cript">
    <!---
    document.onmous emove = getXY;
    document.onmous edown = mousedown;
    document.onmous eup = mouseisup;
    var netscape = (document.layer s) ? 1:0;
    var goodIE = (document.all) ? 1:0;
    var netscape6 = (document.getEl ementById && !document.all) ? 1:0;
    var height = 100;
    var width = 100;
    var left = 50;
    var top = 60;
    var visible = false;
    var mouseX = 0;
    var mouseY = 0;
    var mousedn = false;
    var hspc = 40;
    var vspc = 9;
    var name = 'secondtop';
    var mousePageX;
    var mousePageY;

    document.getEle mentById("top2" ).style.visibil ity="visible";

    function mousedown(e)
    {
    //document.writel n("hello");
    //document.getEle mentById("top2" ).style.visibil ity="visible";
    //mouseX = e.pageX;
    //mouseY = e.pageY;
    //mouseX = mouseX - 29;
    //mouseY = mouseY - vspc;
    //document.getEle mentById("top2" ).style.width=m ouseX;
    mousedn = true;
    //alert("hjiowewe f");
    //var thing;
    }

    // MOUSE MOVE DRAGGING LINE BUT LINE STOPS ON THE IMAGE WORKS OFF THE
    IMAGE THOUGH
    function getXY(e)
    {
    if(mousedn) {
    width = width - 1;
    mouseX = e.pageX;
    mouseY = e.pageY;
    mouseX = mouseX - 29;
    mouseY = mouseY - vspc;
    document.getEle mentById("top2" ).style.width=m ouseX;
    //alert("Mouse Move");
    window.status = "X: " + mouseX + " Y: " + mouseY;
    }
    }

    function mouseisup(e)
    {
    mousedn = false;
    //alert("Mouse UP");
    }

    // -->
    </script>
    </body>
    </html>
  • Rob Swindells

    #2
    Re: document.onmous emove not working quite right help?

    What exactly do you want it to do?

    Rob

    Comment

    • Gary Mayor

      #3
      Re: document.onmous emove not working quite right help?

      Rob Swindells wrote:[color=blue]
      > What exactly do you want it to do?
      >
      > Rob
      > www.avagio.co.uk[/color]

      Hi,
      I want to be able to draw a rectangle over the image using the mouse and
      get the co-ordinates sent to the server.

      With that line if I click the image it seems like it's trying to drag
      the image. How can i turn of the draggin image thing. I don't want a
      drag image just want the onmousemove function to work.

      Thanks


      Gary

      Comment

      • Rob Swindells

        #4
        Re: document.onmous emove not working quite right help?

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
        <head>
        <title>clj</title>
        <meta name="lastupdat ed" content="2004-03-04" />
        <script>
        var drawbox_initial ised;
        var mouse_eventX;
        var mouse_eventY;

        document.onmous edown = init_drawbox;
        document.onmous emove = drawbox;
        document.onmous eup = term_drawbox;

        function init_drawbox( e )
        {
        if ( e )
        {
        mouse_eventX = e.pageX;
        mouse_eventY = e.pageY;
        }
        else
        {
        mouse_eventX = event.x;
        mouse_eventY = event.y;
        }
        document.getEle mentById( 'box' ).style.visibil ity = 'visible';
        document.getEle mentById( 'box' ).style.left = mouse_eventX + 'px';
        document.getEle mentById( 'box' ).style.top = mouse_eventY + 'px';
        drawbox_initial ised = true;
        return false;
        }

        function drawbox( e )
        {
        if ( e )
        {
        mouse_eventX = e.pageX;
        mouse_eventY = e.pageY;
        }
        else
        {
        mouse_eventX = event.x;
        mouse_eventY = event.y;
        }
        if ( drawbox_initial ised )
        {
        document.getEle mentById( 'box' ).style.width = ( mouse_eventX -
        document.getEle mentById( 'box' ).offsetLeft ) + 'px';
        document.getEle mentById( 'box' ).style.height = ( mouse_eventY -
        document.getEle mentById( 'box' ).offsetTop ) + 'px';
        document.getEle mentById( 'coords' ).innerHTML = 'l: ' +
        document.getEle mentById( 'box' ).offsetLeft + 'px, t: ' +
        document.getEle mentById( 'box' ).offsetTop + 'px, w: ' +
        document.getEle mentById( 'box' ).offsetWidth + 'px, h: ' +
        document.getEle mentById( 'box' ).offsetWidth + 'px';
        }
        return false;
        }

        function term_drawbox()
        {
        drawbox_initial ised = false;
        }
        </script>
        <style>
        #box
        {
        border : 1px solid black;
        height : 0px;
        left : 0px;
        position : absolute;
        top : 0px;
        visibility : hidden;
        width : 0px;
        }
        </style>
        </head>
        <body>
        <div id="box"></div>
        <img name="image_tar get"
        src="http://www.google.co.u k/intl/en_uk/images/logo.gif" />
        <div id="coords"></div>
        </body>
        </html>

        Comment

        Working...