Angularjs拖动指令适用于jquery mobile(在手机中)

时间:2018-04-03 07:12:23

标签: angularjs

我是AngularJs的新手,我想要一个指令,当我拖动元素边框时,它会变大或变小,我希望它能在移动设备中工作两个 非常感谢你提前

1 个答案:

答案 0 :(得分:0)

angular.module('resizer', []).directive('resizer', function($document) {

return function(scope, element, attrs) {

    $element.on('mousedown', function(event) {
        event.preventDefault();

        $document.on('mousemove', mousemove);
        $document.on('mouseup', mouseup);
    });

    function mousemove(event) {

        if (attrs.resizer == 'vertical') {
            // Handle vertical resizer
            var x = event.pageX;

            if (attrs.resizerMax && x > attrs.resizerMax) {
                x = parseInt($attrs.resizerMax);
            }

            if (attrs.resizerMax && x < attrs.resizerMin) {
                x = parseInt($attrs.resizerMin);
            }

            element.css({
                left: x + 'px'
            });

            document.getElementById($attrs.resizerLeft.substring(1)).style.width = x + 'px'
            document.getElementById($attrs.resizerRight.substring(1)).style.left = (x + parseInt($attrs.resizerWidth)) + 'px'

        } else {
            // Handle horizontal resizer
            var y = window.innerHeight - event.pageY;

            element.css({
                bottom: y + 'px'
            });

            document.getElementById(attrs.resizerTop.substring(1)).style.bottom = y + 'px'
            document.getElementById(attrs.resizerBottom.substring(1)).style.height = (y + parseInt($attrs.resizerHeight)) + 'px'
        }
    }

    function mouseup() {
        $document.unbind('mousemove', mousemove);
        $document.unbind('mouseup', mouseup);
    }
};

});

以任何方式感谢