正如我在问题中所说,我想要实现的是仅相当于Angular中的代码:
jQuery的方式
$(document).ready(function(){
var windowHeight = $(window).height();
var headerHeight = $('header').height();
var footerHeight = $('footer').height();
var contentHeight = $('.content').height();
var paginationHeight = $('.pagination').height();
var footerMarginTop = (windowHeight - headerHeight - footerHeight) - (contentHeight + paginationHeight);
$('footer').on('content.loaded', function() {
if(footerMarginTop > 0) {
$(this).css('margin-top', footerMarginTop + 'px');
}
}
});
Run Code Online (Sandbox Code Playgroud)
在准备好文档时,我必须在加载页面内容后,根据其他元素的高度计算设置页脚的页边距顶部.在jQuery中思考很容易,但在Angular中,我没有找到其他方法,除了直接翻译它,如此,使用目录
角度方式
angular.module('myApp', []).directive('FooterMargin', ['$window', '$document', function($window, $document){
return {
restrict: 'A',
link: function(scope, element, attrs) {
var windowHeight = $window.innerHeight;
var headerHeight = $document[0].getElementById('header').offsetHeight;
var footerHeight = $document[0].getElementById('footer').offsetHeight;
var paginationHeight …Run Code Online (Sandbox Code Playgroud)