473,396 Members | 1,840 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,396 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 2614
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.