如何检测手风琴元件的高度?

时间:2014-03-27 22:15:18

标签: angularjs twitter-bootstrap

当用户打开手风琴时,我正试图检测手风琴的高度。我正在使用角度引导UI。

我有这样的事情:

<div ng-controller='Ctrl'>
    <accordion id='accordion' close-others="false">
        <accordion-group is-open="false">
            <accordion-heading >                  
                <h2 ng-click='open()'>title</h2>
            </accordion-heading>
            <div>
                <div>
                    lots of content here…..
                </div>
            </div>
        </accordion-group>          
    </accordion>
</div>

我的控制器:

.controller('Ctrl', ['$scope', function ($scope) {
     $scope.open=function(){
        var Height = $('#accordion div').height();
         //The problem is the height is the accordion title div instead of the whole div
         //because it takes time to expand the accordion. 
         //I need to know the entire accordion height 
         //instead of just accordion title height.
    }
}]);

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

也许你可以通过一种棘手的方式实现这一目标:

$scope.open=function(){
  setTimeout(function() {
    var Height = $('#accordion').height();
  }, 1000);
}

答案 1 :(得分:0)

为您的div添加一个ID并使用

获取高度
$scope.open=function(){
    setTimeout(function() {
        var Height = $('#youDivId').height();
    }
}