嗨,我有一张要旋转的图像。左右两个按钮可将图像向相反方向旋转 45 度。我尝试使用 jquery 旋转库创建指令,但它不起作用。帮助?
指令.js
.directive('rotate', function() {
return {
restrict:'A',
link: function(scope, element, attrs) {
console.log('hi');
// watch the degrees attribute, and update the UI when it changes
scope.$watch(attrs.degrees, function(rotateDegrees) {
console.log(rotateDegrees);
//transform the css to rotate based on the new rotateDegrees
element.rotate(rotateDegrees);
});
}
}
});
模板.html
<p><img degrees='angle' rotate id='image' src='myimage.jpg'/> </p>
<a ng-click="rotate('-45')">Rotate Left</a>
<a ng-click="rotate('45')">Rotate Right</a>
控制器.js
$scope.rotate= function(angle) {
$scope.angle=angle;
};