Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect/disable inertial scrolling in Mac Safari?

Tags:

Is there a way to disable or detect that wheel events are from the "inertia" setting on a Mac?

I'd like to be able to tell the difference between real events and the others...or disable that kind of scrolling for a particular page.

like image 317
mherf Avatar asked Dec 02 '10 19:12

mherf


People also ask

What is scroll inertia on Mac?

A new feature called "inertial scrolling" has been introduced in the latest MacBook Pros. This feature changes the way that scrolling functions in OS X, making it behave more like the iPhone. Traditionally, when you use two-finger scrolling in OS X, scrolling stops dead as soon as your fingers stop moving.

How do I stop my MacBook Air from scrolling?

Open your Mac's System Preferences, then click on Trackpad or Mouse. Under trackpad settings, head to “Scroll & Zoom”, then uncheck the “Scroll Direction” option. That's it; you're done!


2 Answers

Yes and no.

You can use touchdown/up, and scroll as events to look for the page moving about but those won't trigger if the OS is doing an inertial scroll. Fun, right?

One thing that you can continually detect, however, is window.pageYOffset. That value will keep changing while an inertial scroll is happening but won't throw an event. So you can come up with a set of timers to keep checking for an inertial scroll and keep running itself until the page has stopped moving.

Tricky stuff, but it should work.

like image 170
OldDrunkenSailor Avatar answered Sep 18 '22 05:09

OldDrunkenSailor


Oh how is this issue killing me :/

I'm in the process of creating "endless" scrolling large file viewer.

To make situation worse, this editor is embedded in page that has its own scroll bar, because its bigger than one screen.

U use overflow-x scroll for horizontal scroll, but for vertical scroll i need current line highlighter (as seen in most modern IDEs) so i'm using jquery mousewheel plugin, and scrolling moving content for line height up or down.

It works perfectly on ubuntu/chrome but on MacOS Lion/Chrome sometimes, and just sometimes, when you scroll, it doesn't prevent default scroll on the editor element, and event propagates "up" and page it self starts to scroll.

I cant even describe how much annoying that is.

As for inertial scroll it self, i successfully reduced it with two timers

var self = this;
// mouse wheel events
    $('#editorWrapper').mousewheel(function (event, delta, deltax, deltay) {

        self._thisScroll = new Date().getTime();


        //
        //this is entirely because of Inertial scrolling feature on mac os :(
        //
        if((self._thisScroll - self._lastScroll) > 5){
            //
            //
            // NOW i do actual moving of content
            //
            //

            self._lastScroll = new Date().getTime(); 
        }

5ms is value i found to have most natural feel on my MacBook Pro, and you have to scroll mouse wheel really fast to catch one of those..

Even still, sometimes on Mac listener on mac wrapper doesn't prevent default, and page scrolls down.

like image 31
kodisha Avatar answered Sep 22 '22 05:09

kodisha