Javascript iPhone Scroll Effect in an iFrame / Javascript Mouse Acceleration

后端 未结 3 1701
长情又很酷
长情又很酷 2021-01-31 21:58

I\'m trying to recreate the iPhone flick / scroll event in a window using JavaScript.

Starting with JQuery, I\'m measuring the mouse\'s acceleration and offset during cl

3条回答
  •  余生分开走
    2021-01-31 23:02

    Hit up this link for the full explanation of one approach that seems to be what you're looking for.

    http://www.faqts.com/knowledge_base/view.phtml/aid/14742/fid/53

    Here's an excerpt:

    This handler then sets up event capture for mouse movement and stores mouse cursor positions in variables mouseX and mouseY. It then starts the timer monitorMouse() which measures mouse cursor speed by sampling the values in these variables at regular intervals. The variables mouseLeft and mouseTop hold each samplings mouse positions and the sampling rate is set to 100 milliseconds in the variable monitor.timerDelay.

    And some of the author's code:

    nn4 = (document.layers)? true:false;
    mouseLeft = mouseTop = mouseX = mouseY = 0;
    monitor = {
        timerDelay:100,
        moveLimit:2,
        sampleLimit:10
    };
    
    function startMonitor(thisText) {
        if (!tip) return;
        toolTipText = thisText;
        writeTooltip(toolTipText);
    
        document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove = function (evt) {
            mouseX = evt.pageX;
            mouseY = evt.pageY;
            return true;
        }
        monitorMouse();
    }
    
    function stopMonitor() {
        if (!tip) return;
        hideTooltip();
            if (monitor.timer) {
            clearTimeout(monitor.timer);
            monitor.timer = null;
        }
        document.releaseEvents(Event.MOUSEMOVE);
        document.onmousemove = null;
        monitor.slowSamples = 0;
    }
    
    function monitorMouse() {
        if (Math.abs(mouseX - mouseLeft)   > monitor.moveLimit
            || Math.abs(mouseY - mouseTop) > monitor.moveLimit)
        {
            monitor.slowSamples = 0;
        }
        else if (++monitor.slowSamples > monitor.sampleLimit) {
            showTooltip();
            return;
        }
        mouseLeft = mouseX;
        mouseTop  = mouseY;
        monitor.timer = setTimeout("monitorMouse()",monitor.timerDelay);
    }
    

提交回复
热议问题