用angularjs旋转svg对象

时间:2017-06-07 11:02:05

标签: javascript angularjs asp.net-mvc svg rotation

我正在使用svg形状,我想旋转这些形状。这是我正在使用的javascript代码:

    $scope.onobjectRotate = function (e)
    { 
        $scope.isSaved = false;
        var draggable = e.currentTarget;
        e.clientX = e.clientX + 20;
        e.clientY = e.clientY + 30;
        var index = parseInt(draggable.attr('data-index'));
        $scope.shapeobjects[index].isactive = true;
        var R2D = 180 * 7 / 22;//radian to degree value(180/pie)
        var center_x = $scope.shapeobjects[index].left + ($scope.shapeobjects[index].width / 2);
        var center_y = $scope.shapeobjects[index].top + ($scope.shapeobjects[index].height / 2);
        x = e.clientX - center_x;
        y = e.clientY - center_y;           
        var radians = y / x;//slope in radians
        var degree = radians * R2D;            
        $scope.shapeobjects[index].rotation = degree;          
        $scope.$apply();
    }

它在某种程度上起作用,因为它只是顺时针方向旋转。但是如何顺时针和逆时针方向旋转呢?

0 个答案:

没有答案