我想打算用 offsetHeight 获取图片的高度 。angular.element(img).ready 这个是dom树加载完就立即执行了。此时图片还没显示出来;所以offsetHeight 获取的高度是0.想用onload 但是在controller 里面好像是无效的。
1 回答

红颜莎娜
TA贡献1842条经验 获得超12个赞
要引入angular版的jquery 叫jqLite
angular.element('#img').height();
或者
angular.element(document.querySelector('#img'))[0].offsetHeight
<body ng-app="myModule"> <h1 my-directive>Hello Plunker! width: {{width}}, height: {{height}} </h1> </body> angular.module('myModule', []) .directive('myDirective', function($timeout) { return { restrict: 'A', link: function(scope, element) { scope.height = element.prop('offsetHeight'); scope.width = element.prop('offsetWidth'); } }; }) ;
添加回答
举报
0/150
提交
取消