Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

trackpad scrolling detected multiple times

var scrolling = false;
var oldTime = 0;
var newTime = 0;
var isTouchPad;
var eventCount = 0;
var eventCountStart;

var mouseHandle = function (evt) {
    var isTouchPadDefined = isTouchPad || typeof isTouchPad !== "undefined";
    console.log(isTouchPadDefined);
    if (!isTouchPadDefined) {
        if (eventCount === 0) {
            eventCountStart = new Date().getTime();
        }

        eventCount++;

        if (new Date().getTime() - eventCountStart > 100) {
                if (eventCount > 10) {
                    isTouchPad = true;
                } else {
                    isTouchPad = false;
                }
            isTouchPadDefined = true;
        }
    }

    if (isTouchPadDefined) {
        // here you can do what you want
        // i just wanted the direction, for swiping, so i have to prevent
        // the multiple event calls to trigger multiple unwanted actions (trackpad)
        if (!evt) evt = event;
        var direction = (evt.detail<0 || evt.wheelDelta>0) ? 1 : -1;

        if (isTouchPad) {
            newTime = new Date().getTime();

            if (!scrolling && newTime-oldTime > 550 ) {
                scrolling = true;
                if (direction < 0) {
                    // swipe down
                } else {
                    // swipe up
                }
                setTimeout(function() {oldTime = new Date().getTime();scrolling = false}, 500);
            }
        } else {
            if (direction < 0) {
                // swipe down
            } else {
                // swipe up
            }
        }
    }
}
document.addEventListener("mousewheel", mouseHandle, false);
document.addEventListener("DOMMouseScroll", mouseHandle, false);
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native charts style gradiant 
Javascript :: splinter wait for input 
Javascript :: mouselight js 
Javascript :: change frame rate javascript 
Javascript :: react Update a label when rate moves "quietly" 
Javascript :: color blur in echart 
Javascript :: provider not found react 
Javascript :: Format Mathjax 
Javascript :: count selected gridview rows in javascript 
Javascript :: codeigniter 4 tooltip dynamic 
Javascript :: how to bind two ng-content in a component angular 
Javascript :: how insert variable dotenv password mangodb 
Javascript :: Webpack: How to compile, write on disk and serve static content (js/css/html/assets) using webpack-dev-server 
Javascript :: span color 
Javascript :: error code ELIFECYCLE REACTJs 
Javascript :: chrome extension sendmessage await until getdata 
Javascript :: rxjs fromevent mouseover 
Javascript :: early exit js 
Javascript :: mapview hooks lag 
Javascript :: Arr::get() The Arr::get method retrieves a value from a deeply nested array using "dot" notation: 
Javascript :: jquery return normal element 
Javascript :: multiple parameters in url Servlet 
Javascript :: markdown config 
Javascript :: nuxt js set background color of body 
Javascript :: how to combine folder for render in express js 
Javascript :: vscode new file crlf 
Javascript :: what is runtime in javascript 
Javascript :: javascript promise multi function error 
Javascript :: dangerously meaning 
Javascript :: reactrouter 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =