繁体   English   中英

我想知道的宽度 <div> 在我的指令模板中,并存储在变量中我该如何实现

[英]i want to know the width of the <div> within my directives template ,and store in the variable how can i achieve that

知道div的宽度

我想知道模板内的宽度,并存储在变量中我该如何实现

 pp.directive('skillSlider',function() { return{ template:'<div class="progress"></div>' } }); ---------- how to calculate the width of the div inside the directive template 

你可以使用link函数来访问元素,使用它可以获得div的宽度。

pp.directive('skillSlider',function()
    {
       return{
              template:'<div class="progress"></div>',

              link:function (scope, element, attrs) {
                console.log(element.width());
               })   
    }
 });     

您可以使用angular.element执行此操作,例如:

angular.element(document.getElementById(id)).clientWidth;
angular.element(document.querySelectorAll('.class')[0]).clientWidth;

或者如果你加载了jQuery

angular.element($('#id').width();
angular.element($('.class')[0]).width();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM