Entry
How can I scroll the window when the mouse cursor approaches the window borders?
Mar 25th, 2001 06:57
Martin Honnen,
The following code that works with NN4, NN6, IE4+ and Opera 5 scroll
down by 100 pixels when the mouse cursor approaches the bottom border
and scrolls up by 100 pixels when the cursor approaches the top border.
<html>
<head>
<script>
if (document.layers)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = function (evt) {
if (document.layers) {
var y = evt.y;
var ty = window.pageYOffset;
var by = window.pageYOffset + window.innerHeight;
}
else if (window.opera) {
var y = evt.clientY;
var ty = window.pageYOffset;
var by = window.pageYOffset + window.innerHeight;
}
else if (document.all) {
var y = event.y + document.body.scrollTop;
var ty = document.body.scrollTop;
var by = document.body.scrollTop + document.body.clientHeight;
}
else if (document.getElementById) {
var y = evt.clientY + window.pageYOffset;
var ty = window.pageYOffset;
var by = window.pageYOffset + window.innerHeight;
}
if (y >= ty && y < ty + 15)
window.scrollBy(0, -100);
else if (y <= by && y > by - 25)
window.scrollBy(0, 100);
}
</script>
</head>
<body>
<script>
for (var i = 0; i < 100; i++)
document.write(i + ' Kibology<br>');
</script>
</body>
</html>