Question

I have implemented a custom scroller, as you can see here. For my scroller I have used ScrollTo. The problem is that I need to understand when the user is using my custom scroller and when it is using mouse or other ways for scrolling, such as keyboard. I tried this:

$(window).scroll(function(){

});

but also my custom scroller triggers this. Here is the structure of my page:

<div class="page">

   <div id="scroller" class="news-scroller">
     <div ><span id="up"></span></div>
     <div ><span id="down"></span></div>
   </div>

   <div class="news">
   </div>
   <div class="news">
   </div>
   ....

and here is the code for my custom scroller:

var current = $(".news").eq(0);

$("#down").click(function(){
   if(current.next().size() > 0)
   {
      current = current.next();
      $.scrollTo("#"+current.attr("id"), 800);     

   }
   else  if(current.next().size() <= 0)
   {
    return
   }
});

$("#up").click(function(){
   if(current.prev().size() > 0)
   {
      current=current.prev();
      $.scrollTo("#"+current.attr("id"), 800);
   }
   else  if(current.prev().size() <= 0)
   {
      return;
   }
});
Était-ce utile?

La solution

Since there might be other people looking for this, here is the conclusion: $(window).scroll() happens with any scrolling event that happens no matter if it is with mouse or keyboard or any kind of scrolling. The only way to somehow diffrenciate them from eachother is to find a pattern in the custom scroller (for example my scroller was scrolling a specific distance in a specific amount of time), which wouldn't be a very accurate solution.

The solution I tried was to trigger a custom event in my custom scroller, in this way I could understand when user is using my custom scroller and when not.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top