detecting end of scroll

W

wolverine

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 there some
other way to know that user has stopped scrolling.

I don't want to use 'onmouseup' since user can scroll using mouse
wheel as well as keyboard. So could any one help me here ?


Thanks in Advance,
Kiran.
 
J

Joost Diepenmaat

wolverine said:
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 there some
other way to know that user has stopped scrolling.

Scroll events work more or less like the onmousemove event; there isn't
really such a thing as 'stop scrolling' or 'stop moving'. There either
is some scrolling within some time period or there isn't.
I don't want to use 'onmouseup' since user can scroll using mouse
wheel as well as keyboard. So could any one help me here ?

You could time out X ms after the last onscroll event. Just like mouse
moves.
 
S

SAM

wolverine a écrit :
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 there some
other way to know that user has stopped scrolling.

I don't want to use 'onmouseup' since user can scroll using mouse
wheel as well as keyboard. So could any one help me here ?


var notScrolling = true;

function scrl() {
var newone = document.body.scrollTop;
if(typeof(old)=='undefined') old = 0;
// action
notScrolling = (old == newone) ;
old = notScrolling? old : newone ;
// repport
if(document.getElementById('scrl'))
document.getElementById('scrl').innerHTML = 'old = '+old+
' - new = ' +newone+ ' - Not scrolling = '+notScrolling;
}
window.onload = function() {
truc = setInterval(scrl, 300);
}




<h2 id="scrl">Scrolling ?</h2>
 
W

wolverine

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 there some
other way to know that user has stopped scrolling.

I don't want to use 'onmouseup' since user can scroll using mouse
wheel as well as keyboard. So could any one help me here ?

Thanks in Advance,
Kiran.

Thanks a lot for all your replies.
 
H

Henry

On Feb 25, 4:26 pm, SAM wrote:
notScrolling = (old == newone) ;
old = notScrolling? old : newone ;
<snip>

That is an odd piece of logic. Your - notScrolling - is true when -
old - equals - newone - and when it is true you assign - old - in the
following line (i.e. whenever - old - and - newone - have the same
value) but when it is false you assign - newone -. That is, - old =
notScrolling? old : newone; - assigns a value that is equal to the
value of - newone - or it assigns the value of - newone -. Why not
forget the test and just assign - newone - to - old - instead?
 
T

Thomas 'PointedEars' Lahn

Joost said:
Scroll events work more or less like the onmousemove event; there isn't
really such a thing as 'stop scrolling' or 'stop moving'. There either
is some scrolling within some time period or there isn't.

In contrast to scrolling, the _mousemove_ event only occurs when the mouse
cursor is moving over the element, meaning that the previous cursor position
was different to the current one. IOW, apples and oranges.
You could time out X ms after the last onscroll event.
Yes.

Just like mouse moves.

No.


PointedEars
 
J

Joost Diepenmaat

Thomas 'PointedEars' Lahn said:
In contrast to scrolling, the _mousemove_ event only occurs when the mouse
cursor is moving over the element, meaning that the previous cursor position
was different to the current one. IOW, apples and oranges.

Are you suggesting that scoll events fire on elements that aren't
scrolled? I don't get your point.
 
S

SAM

Henry a écrit :
On Feb 25, 4:26 pm, SAM wrote:

<snip>

That is an odd piece of logic. Your - notScrolling - is true when -
old - equals - newone - and when it is true you assign - old - in the
following line (i.e. whenever - old - and - newone - have the same
value) but when it is false you assign - newone -. That is, - old =
notScrolling? old : newone; - assigns a value that is equal to the
value of - newone - or it assigns the value of - newone -. Why not
forget the test and just assign - newone - to - old - instead?


'notScrolling' was only for the test-demo, to write/show : 'true/false'
since it exists why not to use it to decide what to do with 'old/newone'
instead to do : old = (old == newone)? old : newone ;

probably : if(old!=newone) old = newoene;
was enough to fix 'old'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top