0

My Question is straight. Is there any way to detect that the scroll to a page has been due to javascript or mouse scroll. I really need to identify the difference.

Is there anybody who can help me to figure out the difference between the scroll made by mouse of a user or it has been due to jQuery or java script scroll event

I am working on a co browsing app, so there is transfer of events among multiple users. I am able to manage all the events except scroll. It lets the system to infinite scroll if scrolling from agent.html is recorded. you can see the app by opening the urls 182.71.103.93/screen2/client23122014.html and then 182.71.103.93/job_tree

  • Listen mousescrolls ... – Teemu Dec 29 '14 at 07:39
  • I am working won a co browsing app, so there is transfer of events among multiple users. I am able to manage all the events except scroll. It lets the system to infinite scroll. you can see the app by opening 182.71.103.93/screen2/client23122014.html and then 182.71.103.93/job_tree – ASHWANI KUMAR SINGH BISEN Dec 29 '14 at 08:35
  • I would like to draw your attention to this question as well http://stackoverflow.com/questions/27653703/socket-io-node-js-mouse-tracking-as-soon-as-it-stops – ASHWANI KUMAR SINGH BISEN Dec 30 '14 at 11:32

2 Answers2

1

Not exactly what you're asking but this will detect a mouse wheel event and therefore if it's not a mousewheel event it's caused by JS. You can use the "mousewheel" ("DOMMouseScroll" in Firefox) event in JS. Example:

// Chrome/Safari/Opera/New IE
$('html','body').addEventListener("mousewheel", MouseWheelHandler, false);

// Firefox
$('html','body').addEventListener("DOMMouseScroll", MouseWheelHandler, false);

// Old IE
$('html','body').addEventListener("onmousewheel", MouseWheelHandler, false);

var MouseWheelHandler = function(e) {
  var e = window.event || e; //IE support
  var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));

  // Do whatever with the delta value
}
Termhn
  • 129
  • 3
  • Your answer is close enough, but what to do if user scrolls the page by dragging page or browser scroller – ASHWANI KUMAR SINGH BISEN Dec 29 '14 at 08:31
  • I am working won a co browsing app, so there is transfer of events among multiple users. I am able to manage all the events except scroll. It lets the system to infinite scroll. you can see the app by opening http://182.71.103.93/screen2/client23122014.html and then http://182.71.103.93/job_tree – ASHWANI KUMAR SINGH BISEN Dec 29 '14 at 08:35
  • Hmm interesting problem. You could try this solution; it's similar to mine but more complete http://stackoverflow.com/questions/2834667/how-can-i-differentiate-a-manual-scroll-via-mousewheel-scrollbar-from-a-javasc – Termhn Dec 29 '14 at 09:05
  • I would like to draw your attention to this question as well http://stackoverflow.com/questions/27653703/socket-io-node-js-mouse-tracking-as-soon-as-it-stops – ASHWANI KUMAR SINGH BISEN Dec 30 '14 at 11:33
0

Answer give by Termhn was good enough but if anyone stuck to the similar situation as of mine then you may use a global javascript variable

i did it in a way

For Client / user side

var emit_scroll_event=true;

socket.on('agentwindowscroll',function (msg){emit_scroll_event=false;  jQuery(document).scrollTop(msg);   });

//window scroll logic goes here
jQuery(document).scroll(function()
{
    var scrollFromTop=jQuery(document).scrollTop();
    if(emit_scroll_event)
    {
    socket.emit('windowscroll', scrollFromTop);
    }
    emit_scroll_event=true;
});

For Agent side we may use similar code

var emit_scroll_event=true;
//agent window scroll logic goes here
jQuery(document).scroll(function()
{
    var scrollFromTop=jQuery(document).scrollTop(); 
    if(emit_scroll_event)
    {
    socket.emit('agentwindowscroll', scrollFromTop);
    }
    emit_scroll_event=true;
});
 //responding to client scroll
  socket.on('windowscroll',function (msg){emit_scroll_event=false;   jQuery(document).scrollTop(msg);   });

Note: This is not entire code. It is just the part of code that i used which helped me to sort out mine issue. It is not for normal javascript. It is used with Node js with Scoket.io module