[英]Make all div same height using directive
I have a web as shown below, 我有一个如下图所示的网络,
There grid is not properly arranged. 网格未正确排列。
When i exected following code in console, it formed the grid correctly. 当我在控制台中预期以下代码时,它正确地形成了网格。
var maxHeight = Math.max.apply(null, $("#activityfeeddetails").find(".course_thumb_outer").map(function (){
return $(this).height();
}).get());
$("#activityfeeddetails").find(".course_thumb_outer").css("height",maxHeight);
screen after executing the code: 执行代码后的屏幕:
Question: How can I add this code in angular directive, so that it executes once all the data and template is loaded. 问题:如何在angular指令中添加此代码,以便在加载所有数据和模板后执行。
Edit : here is the current directive (not working properly), 编辑:这是当前指令(无法正常工作),
dwmProfileDirectives.directive('profileActivityFeedTab', ['Activityfeed', function(Activityfeed) {
return {
restrict: 'E',
scope: {
current:'=current'
},
templateUrl:'tabs/dwm-profile-activity-feed.html',
controller: function($scope) {
$scope.Activityfeeds = Activityfeed.get();
$scope.Activityfeeds.$get().then(function(v){
var maxHeight = Math.max.apply(null, angular.element("#activityfeeddetails").find(".course_thumb_outer").map(function (){
return $(this).height();
}).get());
angular.element("#activityfeeddetails").find(".course_thumb_outer").css("height",maxHeight);
});
}
};
}]);
You can simply fix this issue by setting a min-height
property instead of heigth
and all the elements will have the same heigth of the max heigth element. 您可以通过设置min-height
属性而不是 heigth
来简单地解决此问题,并且所有元素都将具有max heigth元素相同的高度。
So just change this line: 因此,只需更改此行:
angular.element("#activityfeeddetails").find(".course_thumb_outer").css("height",maxHeight);
with the following: 具有以下内容:
angular.element("#activityfeeddetails").find(".course_thumb_outer").css("min-height",maxHeight);
And it should do the trick. 它应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.