[英]What is the correct way to watch an element's height in AngularJS 1.4.8?
[英]What is the angularjs way of changing an elements style based on the height of another element
$('#reply').css("padding-top", $('.post:visible').height()-35 + "px" );
我正在做的是將#reply
的CSS padding-top
值#reply
為.post
的高度。
到目前為止,我可以在我的AngularJS項目中使用此方法的唯一方法是:
$(function() {
setTimeout(function () {
$('#reply').css("padding-top", $('.post:visible').height()-35 + "px" )
},300)
});
我將如何以Angular的方式進行操作,例如,類似的代碼是某種angular.copy
? 或者我可以繼續使用jQuery。 如果是這樣,當AngularJS完成后如何觸發它,所以我不需要超時功能?
<div id="#reply" ng-style="{'padding-top' : code_that_returns_.post:visible's_height }">
這個問題問得很少,但我決定我將逐步解決問題和回答。
目前,這是我的解決方案(它解決了我的超時問題)。
<div id="#reply" ng-style="{'padding-top' : calcPostHeight() }">
$scope.calcPostHeight = function () {
return $('.post:visible').height()-35 + "px";
};
編輯:
該解決方案似乎更糟...但是使用了指令。
<div id="#reply" post-height="35">
.directive('postHeight', function($timeout){
return {
link: {
post: function (scope, element, attr) {
$timeout(function(){
var result = document.getElementsByClassName("post")[0];
element[0].style.paddingTop = result.style.width - attr.postHeight;
}, 0)
}
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.