How do you rotate image in angularjs

前端 未结 3 957
[愿得一人]
[愿得一人] 2021-01-03 03:36

Hi I have an image that I want to rotate. There are two buttons left and right which rotate the image 45 degrees in opposite directions. I tried creating a directive using

3条回答
  •  误落风尘
    2021-01-03 04:17

    You can do the rotation by setting the CSS in the directive

    app.directive('rotate', function () {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                scope.$watch(attrs.degrees, function (rotateDegrees) {
                    console.log(rotateDegrees);
                    var r = 'rotate(' + rotateDegrees + 'deg)';
                    element.css({
                        '-moz-transform': r,
                        '-webkit-transform': r,
                        '-o-transform': r,
                        '-ms-transform': r
                    });
                });
            }
        }
    });
    

    Hope it can shed some light on.

    Demo

提交回复
热议问题