微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – Angularjs根据父元素宽度调整宽度

我正在使用AngularJS& Bootstrap,并具有以下结构:
<parent-div>
  <flexible-width-component 
            class="pull-left" 
            style="display: inline-block; min-width: 700px;">Data grid with many columns
  </flexible-width-component>
  <fixed-width-component 
            class="pull-right" 
            style="width:400px; display: inline-block">
  </fixed-width-component>
</parent-div>

我希望我的柔性宽度分量拉伸能够自动填充自身与固定宽度组件之间的间隙,适用于宽度超过1200px的任何分辨率.
两个组件都需要彼此相邻显示.

任何建议非常感谢!

解决方法

您可以获取父容器offsetWidth并从中减去固定宽度:
var example = angular.module('exmp',[]);

example.directive('flexibleWidth',function() {
    return function(scope,element,attr) {

      // Get parent elmenets width and subtract fixed width
      element.css({ 
        width: element.parent()[0].offsetWidth - 400 + 'px' 
      });

    };
});

这是a demo

原文地址:https://www.jb51.cc/js/158913.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐