简体   繁体   English

在角度材料设计中调整 sidenav 的大小栏。

[英]resize bar for sidenav in angular material design.

Is there a directive in angular material to resize sidenav?角度材料中是否有调整 sidenav 大小的指令?

There is a sidenav which shows list of clients and the right pane has the details of the client.有一个 sidenav 显示客户端列表,右侧窗格包含客户端的详细信息。 I am trying to add a resize bar between them.我正在尝试在它们之间添加一个调整大小栏。

I used the following我使用了以下

http://plnkr.co/edit/Zi2f0EPxmtEUmdoFR63B?p=preview http://plnkr.co/edit/Zi2f0EPxmtEUmdoFR63B?p=preview

which i found in the following我在下面找到的

Angular JS resizable div directive Angular JS 可调整大小的 div 指令

I tried following the above plunker example but the sidenav never resized.我尝试按照上面的 plunker 示例进行操作,但 sidenav 从未调整大小。 The right pane moves right but the left pane remain unchanged.右窗格向右移动,但左窗格保持不变。

<div layout="row" flex>

        <md-sidenav layout="column" class="md-sidenav-left md-whiteframe-z2" id="sidenav" md-component-id="left" md-is-locked-open="$mdMedia('gt-md')">
            <md-list class="sideBar">
                <md-item ng-repeat="client in data">
                    <md-item-content>
                        <md-button ng-click="selectClient(client);" >

                                {{client.name}} 
                        </md-button>
                    </md-item-content>
                </md-item>
            </md-list>
        </md-sidenav>

        <div id="sidebar-resizer" 
        resizer="vertical" 
        resizer-width="6" 
        resizer-left="#sidenav" 
        resizer-right="#primary-col"
        resizer-max="400">
    </div>
    <!-- viewport column -->

    <div layout="column" flex class="content-wrapper" id="primary-col">
        <div id="viewPort" ng-view></div>
    </div>
 </div> 

Thank you谢谢

Found a snippet that can help add resize where ever required and this works well with the Angular Material Design.找到了一个片段,可以帮助在需要的地方添加调整大小,这与 Angular Material Design 配合得很好。

Angularjs version used 1.3.15 and Angular material design version Used is 0.9.8.. Angularjs 版本使用 1.3.15,Angular material design 版本使用的是 0.9.8..

Tested in IE10+ and chrome.在 IE10+ 和 chrome 中测试。

Here is the Git hub link这是 Git 中心链接

https://github.com/Reklino/angular-resizable https://github.com/Reklino/angular-resizable

And here is the working codepen example这是有效的 codepen 示例

http://codepen.io/Reklino/pen/raRaXq http://codepen.io/Reklino/pen/raRaXq

PS-I had issues with the r-flex so I set it to false.It worked fine. 

'width', 'max-width' and 'min-width' all are set to 304px for md-sidenav inside angular-material.css.对于 angular-material.css 中的 md-sidenav,'width'、'max-width' 和 'min-width' 都设置为 304px。 You need to overwrite max & min width values in yr custom.css您需要覆盖 yr custom.css 中的最大和最小宽度值

材质.css

Here is how I constructed a simple sidebar in angular, you may construct a similar things using angularjs or javascript too.这是我如何用 angular 构建一个简单的侧边栏,您也可以使用 angularjs 或 javascript 构建类似的东西。 I have used CSS flexbox model (which has a few resizable properties) in this example with a combination of mouse events.我在这个例子中使用了CSS flexbox模型(它有一些可调整大小的属性)和鼠标事件的组合。

Here is the HTML template:这是 HTML 模板:

<div class="main-container"  (mouseup)="changeResizeMode(false)" (mousemove)="changeLeftContainerWidth($event)" (mouseleave)="changeResizeMode(false)">
    <div class="left-container" [style.flex-basis]="leftContainerWidth">
           <!-- This is the left bar -->    
    </div>
    <div class="resize-handle" (mousedown)="changeResizeMode(true)" (mouseup)="changeResizeMode(false)" [style.background-color]="highlightHandle">
        <div>||</div>
    </div>
    <div class="right-container">
           <!-- This is the right bar -->
    </div>
</div>

Here is the typescript code, where I captured the mouse pointer's x-coordinate using $event object.这是打字稿代码,我使用 $event 对象捕获了鼠标指针的 x 坐标。

  leftContainerWidth: string = '33vw';
  mouseDownOnHandle: boolean = false;
  highlightHandle: string = 'blue';

  changeResizeMode(value: boolean): void{
    this.mouseDownOnHandle = value;
    if(value===true)
      this.highlightHandle = 'green';
    else
      this.highlightHandle = 'blue';
  }
  
  changeLeftContainerWidth(event: MouseEvent): void{
    if(this.mouseDownOnHandle)
      this.leftContainerWidth = event.clientX - 10 + "px";
  }

And finally the CSS code, implementing CSS flexboxes.最后是 CSS 代码,实现 CSS 弹性盒。 :) :)

 .main-container{
     display: flex;
     height: 500px;
 }
   
 .left-container{
     flex-grow: 0;
     flex-shrink: 0;
 }

 .resize-handle{
     flex: 0 0 20px;
     cursor: col-resize;
     display: flex;
     align-items: center;
     justify-content: center;
 }

 .right-container{
     flex: 1 1 50vw;
 }

To answer @LeoLozes: It took me a while (and a coffee break) to figure out the solution.回答@LeoLozes:我花了一段时间(和喝咖啡休息时间)才找到解决方案。 You basically have to wrap the sidenav with another div that is resizable like this您基本上必须用另一个可调整大小的 div 包裹 sidenav

<div resizable r-directions="['left']" r-flex="false">
    <md-sidenav layout="row" class="md-sidenav-right md-whiteframe-2dp" ...>
    </md-sidenav>
</div>

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

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