...

View Full Version : scrollLeft/scrollTop code not working in Firefox



dep
12-27-2005, 05:10 PM
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;

vwphillips
12-27-2005, 05:55 PM
<!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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum