相关疑难解决方法(0)

AngularJS:更好的观察身高变化的方法

我有旧的可变高度导航问题: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)

html javascript css angularjs

37
推荐指数
4
解决办法
8万
查看次数

标签 统计

angularjs ×1

css ×1

html ×1

javascript ×1