如何在 AngularJs 中旋转图像
How can I rotate image in AngularJs
这是我的代码:如何在元素框单击时仅旋转带有 angular 的 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>
单击按钮时使用 ng-class 切换 class。然后在css中使用这个class来旋转图像。
<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);
}
当你的按钮被点击时,你在控制器中处理它并添加一个 class
看看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>
这是我的代码:如何在元素框单击时仅旋转带有 angular 的 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>
单击按钮时使用 ng-class 切换 class。然后在css中使用这个class来旋转图像。
<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);
}
当你的按钮被点击时,你在控制器中处理它并添加一个 class
看看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>