4

这是我的代码:如何在元素框单击时仅旋转带有角度的 svg 箭头?

<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>

这是我的按钮

4

2 回答 2

12

单击按钮时,使用 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);
}
于 2016-04-01T06:58:08.857 回答
0

当你的按钮被点击时,你在控制器中处理它并添加一个类

看看这个

控制器 :

$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>
于 2016-04-01T07:51:18.873 回答