如何在AngularJs中旋转图像

时间:2016-04-01 06:50:24

标签: angularjs angularjs-material

这是我的代码:如何在元素框中单击角度旋转svg-arrow?

<md-card class="header" style="margin: 0 0 4px 0;" ng-mousedown="toggleCollapse('source')">
  <md-card-content layout="row" layout-align="start center">
    <img src="../assets/icons/cd-icon-arrow.svg" class="buildrag-toggle">
    <h2 class="md-title no-top-margin no-bottom-margin" flex style="padding-left: 10px;">Data</h2>
    <md-button class="md-icon-button header-button" ng-mousedown="addDataSource($event)">
      <md-icon>add_circle_outline</md-icon>
    </md-button>
  </md-card-content>
</md-card>

Here is my button

2 个答案:

答案 0 :(得分:11)

单击按钮时,使用ng-class切换类。然后在css中使用此类来旋转图像。

<md-card class="header" style="margin: 0 0 4px 0;" ng-mousedown="toggleCollapse('source')">
  <md-card-content layout="row" layout-align="start center">
    <img src="../assets/icons/cd-icon-arrow.svg" ng-class="{'rotate': rotateImg}" class="buildrag-toggle">
    <h2 class="md-title no-top-margin no-bottom-margin" flex style="padding-left: 10px;">Data</h2>
    <md-button class="md-icon-button header-button" ng-mousedown="addDataSource($event)" ng-click="rotateImg = !rotateImg">
      <md-icon>add_circle_outline</md-icon>
    </md-button>
  </md-card-content>
</md-card>


.rotate {
    -ms-transform: rotate(90deg); /* IE 9 */
    -webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */
    transform: rotate(90deg);
}

答案 1 :(得分:0)

单击按钮后,您可以在控制器中处理它并添加一个类

查看this

控制器:

$scope.todoClicked = function(id) {
console.log("clicked", id);
if (!$scope.showMoreTab[id]) {
  $scope.showMoreTab[id] = true;
  angular.forEach($scope.todos, function(todo) {
    if (id !== todo.id) {
      $scope.showMoreTab[todo.id] = false;
    }
  });
} else {
  $scope.showMoreTab[id] = false;
  }
}

查看:

<md-button class="md-icon-button md-toggle-icon" aria-label="More" ng-click="todoClicked(todo.id)" ng-class="{'toggled':showMoreTab[todo.id]}">
          <i class="material-icons">
            keyboard_arrow_down</i>
        </md-button>

CSS:

.md-toggle-icon.toggled {
  -webkit-transform: rotate(180deg);
   transform: rotate(180deg);
}

我在这里使用了一个图标,但您也可以使用svg进行尝试。

<md-button class="md-icon-button md-toggle-icon" aria-label="More" ng-class="{'toggled':showMoreTab[todo.id]}" ng-click="todoClicked(todo.id)">
                            <md-icon md-svg-src="/material-design-icons/navigation/svg/design/ic_expand_more_36px.svg">
                            </md-icon>
                        </md-button>