leohxj
9/3/2013 - 8:11 AM

鼠标按住的事件处理方式。 From http://segmentfault.com/q/1010000000267088#a-1020000000303243

鼠标按住的事件处理方式。 From http://segmentfault.com/q/1010000000267088#a-1020000000303243

 var interval;

    $('div').mousedown(mouseState).mouseup(mouseState);

    function mouseState(e) {
        if (e.type == "mouseup") {
            clearInterval(interval);
        }
        if (e.type == "mousedown") {
            //code triggers on hold
            interval = setInterval(function () {
                $('div').prepend("<span>hold</span>")
            }, 100);
        }
    }