473,390 Members | 1,414 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,390 software developers and data experts.

Track Scroll Events.

dmjpro
2,476 2GB
How do i track the scroll events in JS. Is there any standard way to do it ?
Please help me ... ;)
Nov 4 '08 #1
16 2613
acoder
16,027 Expert Mod 8TB
Use the onscroll event. It's not part of any standards, but should be reasonably well supported.
Nov 4 '08 #2
dmjpro
2,476 2GB
Use the onscroll event. It's not part of any standards, but should be reasonably well supported.
I test this code in Mozilla...
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var golbal_var = 0;
  3. function test(){
  4.     alert('');
  5.     document.getElementById('text_id').value = ++golbal_var;
  6. }
  7. </script>
  8. </head>
  9.  
  10. <body onScroll=test()>
  11. <input type='text' id='text_id'/>
  12. <div style='width:2000px;height:2000px'/>
  13.  
In Mozilla it's working ..but not in IE ......what should i be doing ??
Nov 4 '08 #3
acoder
16,027 Expert Mod 8TB
For Mozilla compatibility, see MDC.
Nov 4 '08 #4
dmjpro
2,476 2GB
For Mozilla compatibility, see MDC.
Hi ... Acoder thanks!
In IE i had to do .... window.onscroll = function_ref.
Now in both it's working ..... ;)
Nov 4 '08 #5
dmjpro
2,476 2GB
Hi ... Acoder thanks!
In IE i had to do .... window.onscroll = function_ref.
Now in both it's working ..... ;)
Hey Acoder.....
A typical problem appears ...
It's
Expand|Select|Wrap|Line Numbers
  1. alert(document.body.scrollLeft+'\t'+document.body.scrollTop);
always showing value 0 ..no matter which scroll bars scrolled ....
What's wrong with it ..
Nov 4 '08 #6
acoder
16,027 Expert Mod 8TB
Which browser? A quick test in Firefox works.
Nov 4 '08 #7
dmjpro
2,476 2GB
Which browser? A quick test in Firefox works.
I am having this HTML code .....
Expand|Select|Wrap|Line Numbers
  1. <body onLoad = _test()>
  2. <input type='text' id='text_id'/>
  3. <div style='width:2000px;height:2000px' id='div_id'>
  4. </div>
  5. </body>
  6.  
And this is my JavaScript code ..
Expand|Select|Wrap|Line Numbers
  1. function test(){
  2.     alert(document.body.scrollLeft+'\t'+document.body.scrollTop);
  3. }
  4. function _test(){
  5.     window.onscroll = test;
  6. }
  7.  
When horizontal or vertical scroll bars gets scrolled then the both of the values come 0 ...... in Mozilla and in IE both ..
What's wrong with it .... ?
Nov 4 '08 #8
acoder
16,027 Expert Mod 8TB
Again, your code works too in FF, at least. Have you got anything else on the page?
Nov 4 '08 #9
dmjpro
2,476 2GB
Again, your code works too in FF, at least. Have you got anything else on the page?
How strange ..i am getting an alert box with two values ..and both are 0 .....
believe me :(
Nov 4 '08 #10
acoder
16,027 Expert Mod 8TB
I tested with this version of your code:
[html]<html>
<head>
<script>
function test(){
alert(document.body.scrollLeft+'\t'+document.body. scrollTop);
}
function _test(){
window.onscroll = test;
}
</script>
</head>

<body onload = '_test()'>
<input type='text' id='text_id'>
<div style='width:2000px;height:2000px' id='div_id'>
</div>
</body>
</html>[/html]Works in Firefox 3.0.3
Nov 4 '08 #11
dmjpro
2,476 2GB
I tested with this version of your code:
[html]<html>
<head>
<script>
function test(){
alert(document.body.scrollLeft+'\t'+document.body. scrollTop);
}
function _test(){
window.onscroll = test;
}
</script>
</head>

<body onload = '_test()'>
<input type='text' id='text_id'>
<div style='width:2000px;height:2000px' id='div_id'>
</div>
</body>
</html>[/html]Works in Firefox 3.0.3

But mine was Firefox 2.
Whatever it is ...i just wanted to know ..is there any way to position an element at the right most of the page ..... that means according to the position of the scroll bars ...could you guide me to do this ....?
Please ... ;)
Nov 5 '08 #12
acoder
16,027 Expert Mod 8TB
Use "position: fixed" - a simple solution. Set the right property to 0 for it to be fixed to the right side of the window.

Note that position: fixed is not supported in IE 6, but you can make it work using the fix described here.
Nov 5 '08 #13
dmjpro
2,476 2GB
Use "position: fixed" - a simple solution. Set the right property to 0 for it to be fixed to the right side of the window.

Note that position: fixed is not supported in IE 6, but you can make it work using the fix described here.
No no ..... if i scroll down or up ..or scroll horizontally ..at every situation the element should be at the rightmost corner of the page ..i think now u got my point ... ;)
That's why i tried to track the scroll event ... :)
Nov 5 '08 #14
acoder
16,027 Expert Mod 8TB
Then you didn't understand what position: fixed does. That's exactly what you need.

See this modified example:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. #text_id {
  5.   position:fixed;
  6.   top:0px;
  7.   right:0px;
  8. }
  9. </style>
  10. </head>
  11.  
  12. <body>
  13. <input type='text' id='text_id'/>
  14. <div style='width:2000px;height:2000px' id='div_id'>
  15. </div>
  16. </body>
  17. </html>
Nov 5 '08 #15
dmjpro
2,476 2GB
I tested this code ..in IE 6 ..but it's not running ...
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. <head>
  7. <style type="text/css">
  8. #text_id {
  9. position:fixed;
  10. top:0px;
  11. right:0px;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <input type='text' class='text_id'/>
  17. <div style='width:2000px;height:2000px' id='div_id'>
  18. </div>
  19. </body>
  20. </html>
  21.  
Where i am wrong ... :(

Sorry sorry .... i didn't read out your previous post ... ;)

I also tested it in Mozilla ...it's not working ....
Nov 5 '08 #16
acoder
16,027 Expert Mod 8TB
IE 6 doesn't support position:fixed as I mentioned earlier. Use the fix that's described on the page I linked to earlier - Making Internet Explorer use position:fixed;

I'm not sure why it's not working for you in Firefox. It has done for a number of versions. Does the example in that link work?
Nov 5 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: news.microsoft.com | last post by:
Hi, When I process a HScroll scroll event I get one event fired for a increase value using the > button. When I make a User control with a HScroll on it and catch the message and forward my...
12
by: Scott Simonson | last post by:
Does anyone have any idea why Access's module editor doesn't scroll with the mouse. I noticed this behavor in Access 2k also. While viewing code in a module (or any thing for that matter) the wheel...
3
by: Benny Raymond | last post by:
I've looked around msdn for about an hour now and can't figure out how to place an event when the user scrolls, or even how to get the value of where the scroll bar is actually placed... Anyone...
1
by: Code Monkey | last post by:
using VS2005 and c# to create a windows forms application. One of my forms has a panel which I've added various controls to. Now, I've set the autoscroll property to true, which is great, but I...
0
by: brianpmccullough | last post by:
Hello, Anyone ever implemented a solution that allows you to track the total page request time in and ASP.NET page? The time would need to include the server processing time and client side...
4
by: Stevo | last post by:
I need to lock a DIV in place so that regardless of the scroll position, it remains stuck in a corner. Currently I'm hooked into the scroll events and I'm positioning dynamically based on the...
4
by: wolverine | last post by:
Hi, I want to know when user has stopped scrolling. I can know the beginning of a scroll by attaching the 'onscroll' event. But how do i detect end of scroll. Is there any event for that ? Or is...
5
by: konryd | last post by:
I want to know when a user scrolls the textarea. Since there is no such an event, I need to scroll all the ways scrolling might be invoked, that is: * by pressing keys * by moving mouse * by...
2
by: Steven | last post by:
Hello, I want to raise the ValueChanged event ONLY when i move the track bar manually, but not the value changed, how to do in the event below? thank you Private Sub TrackBar1_ValueChanged(ByVal...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.