How to distinguish scrolling by mouse from scrolling programmatically in JavaScript?

You could use the hover() : function to stop the scrolling when the mouse is over the scrollbox element.

You could use the .hover(): function to stop the scrolling when the mouse is over the scrollbox element: jsfiddle.net/bGHAH/1/ setInterval(function(){ if(!mouseover) { $('#scrollbox'). ScrollLeft($('#scrollbox').scrollLeft()+1); } }, 50); var mouseover = false; $('#scrollbox'). Hover(function(){ mouseover = true; },function(){ mouseover = false; }); Edit Based on your comments I managed to find a jquery plugin from the following site: special scroll events for jquery.

This plugin contains an event which attempts to determine whether scrolling has stopped based on the period of time that has elapsed between the last scroll step and the time the check was made. To get this to work I needed to slow your interval to just over the latency used by the plugin which worked out to be 310 milliseconds. Doing this meant I had to increase the scroll step to keep it visibly moving.

Here is the link: jsfiddle.net/EWACn/1/ and here is the code: var stopAutoScroll = false; $(document). Ready(function(){ setInterval(function(){ if(!stopAutoScroll) { $('#status'). Html('scrolling'); $('#scrollbox').

ScrollLeft($('#scrollbox').scrollLeft()+10); }else{ $('#status'). Html('not scrolling'); } }, 310); $('#scrollbox'). Bind('scrollstart', function(e){ stopAutoScroll = true; }); $('#scrollbox').

Bind('scrollstop', function(e){ stopAutoScroll = false; }); }); Hope this helps.

That's not practical because the DIV fills the whole client area, so the mouse is over it most of the time (without scrolling) – travelboy Aug 24 at 17:15 I ended up using a work-around (in the scroll event handler I save the last position and check if the scroll distance is 1px. If so, I assume it occurred from the programmatic scrolling, else from the mouse). But this is definitely a cool method, so I'll accept this answer.

Many thanks! – travelboy Aug 24 at 21:06.

For FF (Mozilla): document. AddEventListener('DOMMouseScroll', handler, false); For IE, Opera and Chrome: document. Onmousewheel = handler.

Another option is to have an external flag that you can set prior to the programmatic scrolling, and then reset afterwords. If the scroll event is fired and this flag isn't set you know that the user is responsible and can act accordingly. Unfortunately while this is browser independent and easy to read it could lead you to believe that some user scrolls are programmatic ones.

However I would think the occurrences of this is small and may be worth it depending on the app you are writing.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions