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

AngularJS:观察高度变化的更好方法,第1张

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

这通过注册一个

emHeightSource
名为every
观察者来工作
$digest
。它会更新该
__height
属性,该属性又将在监视
emHeightTarget

.directive( 'emHeightTarget', function() {    return {        link: function( scope, elem, attrs ) { scope.$watch( '__height', function( newHeight, oldHeight ) {     elem.attr( 'style', 'margin-top: ' + (58 + newHeight) + 'px' ); } );        }    }} ).directive( 'emHeightSource', function() {    return {        link: function( scope, elem, attrs ) { scope.$watch( function() {     scope.__height = elem.height(); } );        }    }} )


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5673962.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存