473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

window scroll detection

abs
How to detect that user started to scroll the page ? Separately vertical and
horizontal scroll. Is it possible ?

Regards,
ABS
Jul 23 '05 #1
2 9896
abs wrote:
How to detect that user started to scroll the page ? Separately vertical and
horizontal scroll. Is it possible ?


I used a setInterval timer that you can set to check at any interval (in
milliSeconds, 1000 mS = 1 second). I have this set to check for a
vertical or horizontal scroll every 1 second, it works on my IE6,
Netscape 7.2, Firefox 1.0. Not sure what it will do in other browsers.
If you know what browsers you need it to work on and have them
installed, you can test for their properties and add their measurements
to the functions.

Mike

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Detect Scrolling</title>
<style type="text/css">
body{
margin: 50px;
padding: 50px;
}
..wrapper{
width: 500px;
scrolling: auto;
border: 1px solid green;
position: absolute;
}
</style>
<script type="text/javascript">
var lastX, lastY, currentX, currentY;
function recordbeginvalues(){
if (document.getElementById&&!document.all){
lastY=window.pageYOffset;
lastX=window.pageXOffset;
}else{
lastY=document.documentElement.scrollTop;
lastX=document.documentElement.scrollLeft;
}
startPolling();
}
function startPolling(){setInterval("poll()",1000)}
function poll(){
if (document.getElementById&&!document.all){
currentY=window.pageYOffset;
currentX=window.pageXOffset;
}else{
currentY=document.documentElement.scrollTop;
currentX=document.documentElement.scrollLeft;
}
if (lastX!=currentX || lastY!=currentY){
alert('The Page Was Scrolled\n lastX '+lastX+' currentX
'+currentX+'\n lastY '+lastY+' currentY '+currentY);
lastX=currentX;
lastY=currentY;
}
}
</script>
</head>

<body bgcolor="#ffffff" onLoad="recordbeginvalues();">
<div class='wrapper'>
<p><b>This page will change background colors depending on how far down
you scroll.</b></p>
<p>Some bogus text to creat scrolling:</p>
<p>NOTE: PLACE LARGE AMT TEXT HERE TO FORCE THE SCROLLBARS TO APPEAR.
<br>
<br>
<br>
<br>
<p>NOTE: PLACE LARGE AMT TEXT HERE TO FORCE THE SCROLLBARS TO APPEAR.
<br>
<br>
<br>
<br>
<p>NOTE: PLACE LARGE AMT TEXT HERE TO FORCE THE SCROLLBARS TO APPEAR.
<br>
<br>
<br>
<br>
<p>NOTE: PLACE LARGE AMT TEXT HERE TO FORCE THE SCROLLBARS TO APPEAR.
<br>
<br>
<br>
<br>
<p>NOTE: PLACE LARGE AMT TEXT HERE TO FORCE THE SCROLLBARS TO APPEAR.
<br>
<br>
<br>
<br>
</p>
</div>
</body>
</html>
Jul 23 '05 #2
On Sat, 12 Feb 2005 23:09:51 +0100 abs wrote:
How to detect that user started to scroll the page ? Separately
vertical and
horizontal scroll. Is it possible ? Regards,
ABS

Why would you need to know that?
There are some things that are better off left alone.
If you don't want a visitor to scroll, then design the page so there is no
scroll needed.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Christopher Benson-Manica | last post by:
In some old Javascript we have, we try to determine whether the client is IE or Netscape (assume for the purposes of this question that the question can be resolved satisfactorily) and tailor the...
8
by: ed | last post by:
Does anyone know if ASP.NET 2.0 is going to incorporate "maintain scroll position on postback" in non-IE browsers like Firefox? This seems like an often requested feature on these newsgroups...
19
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). ...
2
by: Sachin | last post by:
To display the vertical scroll bar of any control (Print Preview Control in perticular)which window message is set? pls guide -- sachin
3
by: Steve | last post by:
I want to force a window to scroll and am finding this to be an impossibly difficult task. First I tried using the API functions ScrollWindow and ScrollWindowEx but they do not work. The portion...
4
by: fidodido | last post by:
If i press the button "MOVE UP", it will go to the top of the select box. If i press the button "MOVE DOWN", it will go to the bottom of the select box. The selected values that the user select...
2
by: usenet | last post by:
When I open a form design window in Access 2003 it *always* has scroll bars, this is even when the form itself is tiny. It's as if the 'page' on which the form is being designed is very large. ...
6
by: Frank Rizzo | last post by:
I am using the Immediate Window a lot to see the progress of the application. In VS2003, if your cursor was at the very bottom, the window would scroll down whenever something new showed up. If...
6
by: Tweety | last post by:
Hello, I need to display the current Web Browser's Width on my web page. I Tried Screen.width, but it is for the width of the Windows. I tried Window.width, but it doesn't work. What i want...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.