当同时单击鼠标左键时,clearInterval不起作用

时间:2017-06-03 17:27:24

标签: javascript jquery


    myDirectives.directive("mouseholdevent", function () {
    return {
        restrict: 'A',
        link: function (scope, element) {
            var el = element[0];
            el.mousehold = true;
            var setint = '';
            var rightClick = false;
            ele(element).mousedown(function (e) {
                setint = setInterval(function () {
                    if (rightClick) {
                        clearInterval(setint);
                    } else {
                        if (element.hasClass("zoom_out")) {
                            scope.zoomOutOnCanvasImage();
                        } else if (element.hasClass("zoom_in")) {
                            scope.zoomInOnCanvasImage();
                        }
                    }
                }, 100);
            });
            ele(element).on("mouseleave mouseup contextmenu", function () {
                rightClick = true;
                clearInterval(setint);
            });
        }
    };
});

1 个答案:

答案 0 :(得分:0)


    myDirectives.directive("mouseholdevent", function () {
    return {
        restrict: 'A',
        link: function (scope, element) {
            var setint = '';
            ele(element).mousedown(function (e) {
                clearInterval(setint);
                if (e.button === 2) {
                    return false;
                }
                setint = setInterval(function () {
                    if (element.hasClass("zoom_out")) {
                        scope.zoomOutOnCanvasImage();
                    } else if (element.hasClass("zoom_in")) {
                        scope.zoomInOnCanvasImage();
                    }
                }, 100);
            });
            ele(element).on("mouseleave mouseup", function () {
                clearInterval(setint);
            });
        }
    };
});