我有旧的可变高度导航问题:position: fixes顶部导航和margin-top: $naviHeight下面的内容.当数据异步加载时导航可以改变高度,因此内容的边距必须随之改变.
我希望这是自成一体的.所以没有加载数据的代码,只有在涉及的html-elements /指令中.
目前我在AngularJS 1.2.0中使用这样的计时器:
/*
* Get notified when height changes and change margin-top
*/
.directive( 'emHeightTarget', function(){
return {
link: function( scope, elem, attrs ){
scope.$on( 'heightchange', function( ev, newHeight ){
elem.attr( 'style', 'margin-top: ' + (58+newHeight) + 'px' );
} );
}
}
})
/*
* Checks this element periodically for height changes
*/
.directive( 'emHeightSource', ['$timeout', function( $timeout ) {
return {
link: function( scope, elem, attrs ){
function __check(){ …Run Code Online (Sandbox Code Playgroud)