How do i track the scroll events in JS. Is there any standard way to do it ?
Please help me ... ;)
16 2614
Use the onscroll event. It's not part of any standards, but should be reasonably well supported.
Use the onscroll event. It's not part of any standards, but should be reasonably well supported.
I test this code in Mozilla... -
<script type="text/javascript">
-
var golbal_var = 0;
-
function test(){
-
alert('');
-
document.getElementById('text_id').value = ++golbal_var;
-
}
-
</script>
-
</head>
-
-
<body onScroll=test()>
-
<input type='text' id='text_id'/>
-
<div style='width:2000px;height:2000px'/>
-
In Mozilla it's working ..but not in IE ......what should i be doing ??
For Mozilla compatibility, see MDC.
For Mozilla compatibility, see MDC.
Hi ... Acoder thanks!
In IE i had to do .... window.onscroll = function_ref.
Now in both it's working ..... ;)
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 - alert(document.body.scrollLeft+'\t'+document.body.scrollTop);
always showing value 0 ..no matter which scroll bars scrolled ....
What's wrong with it ..
Which browser? A quick test in Firefox works.
Which browser? A quick test in Firefox works.
I am having this HTML code ..... -
<body onLoad = _test()>
-
<input type='text' id='text_id'/>
-
<div style='width:2000px;height:2000px' id='div_id'>
-
</div>
-
</body>
-
And this is my JavaScript code .. -
function test(){
-
alert(document.body.scrollLeft+'\t'+document.body.scrollTop);
-
}
-
function _test(){
-
window.onscroll = test;
-
}
-
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 .... ?
Again, your code works too in FF, at least. Have you got anything else on the page?
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 :(
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
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 ... ;)
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.
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 ... :)
Then you didn't understand what position: fixed does. That's exactly what you need.
See this modified example: - <html>
-
<head>
-
<style type="text/css">
-
#text_id {
-
position:fixed;
-
top:0px;
-
right:0px;
-
}
-
</style>
-
</head>
-
-
<body>
-
<input type='text' id='text_id'/>
-
<div style='width:2000px;height:2000px' id='div_id'>
-
</div>
-
</body>
-
</html>
I tested this code ..in IE 6 ..but it's not running ... -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<title>Untitled Document</title>
-
<head>
-
<style type="text/css">
-
#text_id {
-
position:fixed;
-
top:0px;
-
right:0px;
-
}
-
</style>
-
</head>
-
<body>
-
<input type='text' class='text_id'/>
-
<div style='width:2000px;height:2000px' id='div_id'>
-
</div>
-
</body>
-
</html>
-
Where i am wrong ... :(
Sorry sorry .... i didn't read out your previous post ... ;)
I also tested it in Mozilla ...it's not working ....
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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: 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...
|
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...
|
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,...
| |