Knowledge Base Nr: 00274 ajax10.txt - http://www.swe-kaiser.de

Ajax: automatisches scrollen des dokuments

  
<style type="text/css">
<!--
body { position: absolute;
top: 0px;
left: 0px;
}
-->
</style>

<script>
function doScroll(event)
{
if (!event)
event = window.event;

//size of page
var xP,yP;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
xP = document.body.scrollWidth;
yP = document.body.scrollHeight;
}
else //Explorer Mac - would also work in Explorer 6 Strict, Mozilla and Safari
{
xP = document.body.offsetWidth;
yP = document.body.offsetHeight;
}

//size of window
var xW,yW;
if (self.innerHeight) // all except Explorer
{
xW = self.innerWidth;
yW = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
{
xW = document.documentElement.clientWidth;
yW = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
xW = document.body.clientWidth;
yW = document.body.clientHeight;
}

xW += 150;
yW -= 150;

//mouse position
var xM = event.clientX;
var yM = event.clientY;

var oBody = document.getElementById("mybody");

var x = -(xM * (xP/xW)); if (x>-20) x = 20;
var y = -(yM * (yP/yW)); if (y>-20) y = 20;

//alert("pP:" + xP + "/" + yP + "\npW:" + xW + "/" + yW + "\npM:" + xM + "/" + yM);
oBody.style.left = x + "px";
oBody.style.top = y + "px";
}

document.onmousemove = doScroll;
</script>

<body id="body" onmousemove="doScroll(event);" onmouseout="doReset();">