Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    dep
    dep is offline
    Regular Coder
    Join Date
    Nov 2005
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts

    scrollLeft/scrollTop code not working in Firefox

    Any ideas why this might not be working in Firefox? Works fine in IE.

    var IE = document.all?true:false

    // Temporary variables to hold mouse x-y pos.s
    var tempX = 0
    var tempY = 0
    var e = new Object();

    // Main function to retrieve mouse x-y pos.s
    if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
    } else { // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
    }
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 0}
    if (tempY < 0){tempY = 0}
    // show the position values

    alert(tempX + ' ' + tempY);

    document.getElementById("popupWindow").style.left = tempX + 15;
    document.getElementById("popupWindow").style.top = tempY - 100;

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,522
    Thanks
    3
    Thanked 508 Times in 495 Posts
    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">
    <!--
    var IE = document.all?true:false
    
    // Temporary variables to hold mouse x-y pos.s
    var tempX = 0
    var tempY = 0
    var e = new Object();
    function Test(e){
    document.Show.Show2.value=vic;
    
    // Main function to retrieve mouse x-y pos.s
    if (IE) { // grab the x-y pos.s if browser is IE
     tempX = event.clientX + document.body.scrollLeft
     tempY = event.clientY + document.body.scrollTop
    } else { // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
    }
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 0}
    if (tempY < 0){tempY = 0}
    // show the position values
    
    document.Show.Show1.value=tempX + ' ' + tempY;
    
    document.getElementById("popupWindow").style.left = (tempX + 15)+'px';
     document.getElementById("popupWindow").style.top = (tempY - 100)+'px';
    }
    
    document.onmousemove=function(event){ Test(event); }
    
    //-->
    </script></head>
    
    <body>
    <img id="popupWindow" src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" style="position:absolute;" >
    <script> vic=0; </script>
    <form name=Show id=Show style="position:absolute;visibility:visible;top:450px;left:0px;" >
    <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 >
    </form>
    </body>
    
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •