【问题标题】:Watch on actual size of element观察元素的实际尺寸
【发布时间】:2014-11-08 12:57:56
【问题描述】:

我正在尝试创建一个指令来监视另一个 div 元素的大小。

我有这个代码:

link: function(scope, element, attrs) {
      var win = angular.element($('#id'));
      win.bind('resize', function(e) {
        alert(win.height());
      });
    }

元素 #id 的宽度 = 100% 和高度 = 100%。当我调整窗口大小时,并没有发生。 那么,我该怎么做才能获得实际的 win.height?

【问题讨论】:

    标签: angularjs angularjs-directive


    【解决方案1】:
    win.bind('resize', function(event) {
        var height;
    
        height = event.currentTarget.clientHeight // with padding
        // or .offsetHeight (contains the height with the padding, scroll bar, and the border)
    
        alert(height);
    });
    

    【讨论】:

      猜你喜欢
      • 2021-05-22
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 2023-03-09
      • 2010-12-07
      • 2012-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多