event not working with firefox and NS7

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oscar Monteiro

    #1

    event not working with firefox and NS7

    the Code below captures the Mouse move event, while event isn´t defined
    anywhere it still works in IE only, how can I define the event handler so it
    can work with other browsers, Firefox mostly.
    -------snipped code-------------
    Ymouse = -50;
    Xmouse = -50;

    function Mouse(evnt) {
    Ymouse=event.y-20;
    Xmouse=event.x;
    }
    ----------------------------------

    the hole code:
    <SCRIPT type="text/javascript">

    Image0 = new Image();
    Image0.src = "sailormoon.jpg ";
    Amount = 20;
    Ymouse = -50;
    Xmouse = -50;
    Ypos = new Array();
    Xpos = new Array();
    Speed = new Array();
    rate = new Array();
    grow = new Array();
    Step = new Array();
    Cstep = new Array();
    nsSize = new Array();


    function Mouse(evnt) {
    Ymouse=event.y-20;
    Xmouse=event.x;
    }
    document.onmous emove=Mouse;
    for (i = 0; i < Amount; i++) {
    Ypos[i] = Ymouse;
    Xpos[i] = Xmouse;
    Speed[i] = Math.random()*4 +1;
    Cstep[i] = 0;
    Step[i] = Math.random()*0 .1+0.05;
    grow[i] = 8;
    nsSize[i] = Math.random()*1 5+5;
    rate[i] = Math.random()*0 .5+0.1;
    }

    document.write( '<div style="position :absolute;top:0 px;left:0px"><d iv
    style="position :relative">');
    for (i = 0; i < Amount; i++) {
    document.write( '<img id="si'+i+'" src="'+Image0.s rc+'"
    style="position :absolute;top:0 px;left:0px;fil ter:alpha(opaci ty=90)">');
    }
    document.write( '</div></div>');

    function MouseBubbles() {
    var hscrll=document .body.scrollTop ;
    var wscrll=document .body.scrollLef t;
    for (i = 0; i < Amount; i++){
    sy = Speed[i] * Math.sin(270 * Math.PI / 180);
    sx = Speed[i] * Math.cos(Cstep[i] * 4);
    Ypos[i] += sy;
    Xpos[i] += sx;
    if (Ypos[i] < -40) {
    Ypos[i] = Ymouse;
    Xpos[i] = Xmouse;
    Speed[i] = Math.random() * 6 + 4;
    grow[i] = 8;
    nsSize[i] = Math.random() * 15 + 5;
    }

    document.getEle mentById("si"+i ).style.pixelLe ft = Xpos[i] + wscrll;
    document.getEle mentById("si"+i ).style.pixelTo p = Ypos[i] + hscrll;
    document.getEle mentById("si"+i ).style.width = grow[i];
    document.getEle mentById("si"+i ).style.height = grow[i];

    grow[i] += rate[i];
    Cstep[i] += Step[i];
    if (grow[i] > 24) grow[i] = 25;
    }
    setTimeout('Mou seBubbles()', 10);
    }
    MouseBubbles();

    </script>

    wish you all a nice weekend , and many thank for the help
    in the previous posts.

    Best Regards


  • Fred Oz

    #2
    Re: event not working with firefox and NS7

    Oscar Monteiro wrote:[color=blue]
    > the Code below captures the Mouse move event, while event isn´t defined
    > anywhere it still works in IE only, how can I define the event handler so it
    > can work with other browsers, Firefox mostly.
    > -------snipped code-------------
    > Ymouse = -50;
    > Xmouse = -50;
    >
    > function Mouse(evnt) {[/color]

    Add this line right after the function declaration:

    var e = evnt || window.event;

    then just use "e" rather than "event".
    [color=blue]
    > Ymouse=event.y-20;
    > Xmouse=event.x;[/color]

    becomes:

    Ymouse = e.y-20;
    Xmouse = e.x;

    You can also add support for older Netscape with:

    Ymouse = e.y-20 || e.layerY-20;
    Xmouse = e.x || e.layerX;

    Untested, but see how you go.

    --
    Fred

    Comment

    • Oscar Monteiro

      #3
      Re: event not working with firefox and NS7


      "Fred Oz" <ozfred@iinet.n et.auau> escreveu na mensagem
      news:420cb55e$0 $25037$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
      > Oscar Monteiro wrote:[color=green]
      >> the Code below captures the Mouse move event, while event isn´t defined
      >> anywhere it still works in IE only, how can I define the event handler so
      >> it can work with other browsers, Firefox mostly.
      >> -------snipped code-------------
      >> Ymouse = -50;
      >> Xmouse = -50;
      >>
      >> function Mouse(evnt) {[/color]
      >
      > Add this line right after the function declaration:
      >
      > var e = evnt || window.event;
      >
      > then just use "e" rather than "event".
      >[color=green]
      >> Ymouse=event.y-20;
      >> Xmouse=event.x;[/color]
      >
      > becomes:
      >
      > Ymouse = e.y-20;
      > Xmouse = e.x;
      >
      > You can also add support for older Netscape with:
      >
      > Ymouse = e.y-20 || e.layerY-20;
      > Xmouse = e.x || e.layerX;
      >
      > Untested, but see how you go.
      >
      > --
      > Fred[/color]

      Thanks for helping me deffining the event handler Fred still lacks something
      to track mouse movement .
      Thanks anyway for the help given.


      Comment

      • Fred Oz

        #4
        Re: event not working with firefox and NS7

        Oscar Monteiro wrote:
        [...][color=blue]
        >
        > Thanks for helping me deffining the event handler Fred still lacks something
        > to track mouse movement .
        > Thanks anyway for the help given.
        >[/color]

        There was more than one issue, modified code below (original
        commented out mostly)


        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        <html>
        <head>
        <title>mouse move</title>
        </head>
        <body>
        <span id="theSpot"></span>

        <SCRIPT type="text/javascript">
        Image0 = new Image();
        // Image0.src = "sailormoon.jpg ";
        Image0.src = "a.jpg";
        Amount = 20;
        Ymouse = -50;
        Xmouse = -50;
        Ypos = new Array();
        Xpos = new Array();
        Speed = new Array();
        rate = new Array();
        grow = new Array();
        Step = new Array();
        Cstep = new Array();
        nsSize = new Array();

        docBody = document.getEle mentsByTagName( 'body')[0];
        // debug
        // spot = document.getEle mentById('theSp ot');

        function Mouse(event) {
        var e = event || window.event;
        // Ymouse= e.y-20;
        // Xmouse= e.x;
        // clientX/Y works in IE too, is OR needed still?
        Ymouse= e.clientY-20 || e.y-20;
        Xmouse= e.clientX || e.x;
        }

        document.onmous emove = Mouse;
        for (i = 0; i < Amount; i++) {
        Ypos[i] = Ymouse;
        Xpos[i] = Xmouse;
        Speed[i] = Math.random()*4 +1;
        Cstep[i] = 0;
        Step[i] = Math.random()*0 .1+0.05;
        grow[i] = 8;
        nsSize[i] = Math.random()*1 5+5;
        rate[i] = Math.random()*0 .5+0.1;
        }

        var aDiv = document.create Element('div');
        aDiv.style.posi tion = 'absolute';
        aDiv.style.top = '0';
        aDiv.style.left = '0';

        var bDiv = document.create Element('div');
        bDiv.style.posi tion = 'relative';
        for (i = 0; i < Amount; i++) {
        var oImg = document.create Element('img');
        oImg.id = 'si' + i;
        oImg.src = Image0.src;
        oImg.style.posi tion = 'absolute';
        oImg.style.top = '0';
        oImg.style.left = '0';
        oImg.style.filt er = 'alpha(opacity= 90)';

        bDiv.appendChil d(oImg);
        }

        aDiv.appendChil d(bDiv);
        docBody.appendC hild(aDiv);

        /*
        // replaced with DOM methods above
        document.write( '<div style="position :absolute;top:0 px;'
        + 'left:0px"><div style="position :relative">');
        for (i = 0; i < Amount; i++) {
        document.write( '<img id="si'+i+'" src="'+Image0.s rc+'" '
        + 'style="positio n:absolute;top: 0px;left:0px;fi lter:'
        + 'alpha(opacity= 90)">');
        }

        document.write( '</div></div>');
        */

        function MouseBubbles() {
        var hscrll=document .body.scrollTop ;
        var wscrll=document .body.scrollLef t;
        for (i = 0; i < Amount; i++){
        sy = Speed[i] * Math.sin(270 * Math.PI / 180);
        sx = Speed[i] * Math.cos(Cstep[i] * 4);
        Ypos[i] += sy;
        Xpos[i] += sx;

        // debug
        // if (i<5)
        // spot.innerHTML = Ypos.join(' ') + '\n' + Xpos.join(' ');

        if (Ypos[i] < -40) {
        Ypos[i] = Ymouse;
        Xpos[i] = Xmouse;
        Speed[i] = Math.random() * 6 + 4;
        grow[i] = 8;
        nsSize[i] = Math.random() * 15 + 5;
        }

        // pixelLeft not supported by Firefox, just use left
        // (works in IE too)
        // document.getEle mentById("si"+i ).style.pixelLe ft = Xpos[i]
        // + wscrll;
        // document.getEle mentById("si"+i ).style.pixelTo p = Ypos[i]
        // + hscrll;
        document.getEle mentById("si"+i ).style.left = Xpos[i] + wscrll;
        document.getEle mentById("si"+i ).style.top = Ypos[i] + hscrll;
        document.getEle mentById("si"+i ).style.width = grow[i];
        document.getEle mentById("si"+i ).style.height = grow[i];

        grow[i] += rate[i];
        Cstep[i] += Step[i];

        if (grow[i] > 24) grow[i] = 25;
        }
        setTimeout('Mou seBubbles()', 10);
        }
        MouseBubbles();
        </script>
        </body>
        </html>


        --
        Fred.

        Comment

        • Fred Oz

          #5
          Re: event not working with firefox and NS7

          Fred Oz wrote:[color=blue]
          > Oscar Monteiro wrote:
          > [...]
          >[color=green]
          >>
          >> Thanks for helping me deffining the event handler Fred still lacks
          >> something to track mouse movement .
          >> Thanks anyway for the help given.
          >>[/color]
          >
          > There was more than one issue, modified code below (original
          > commented out mostly)[/color]
          [...]


          Tested and working in Safari too.


          --
          Fred

          Comment

          Working...