简体   繁体   English

带有包装和响应的Angular cdk-virtual-scroll

[英]Angular cdk-virtual-scroll with wrap and responsiveness

I am looking at the cdk-virtual-scroll and hoping I can use this in my existing application, where I have a view containing items, who's width varies depending on screen size (eg phone vs tablet etc) 我正在查看cdk-virtual-scroll并希望我可以在我现有的应用程序中使用它,我有一个包含项目的视图,其宽度因屏幕大小而异(例如手机与平板电脑等)

Forking this example , I have a modified version here . 这个例子中 ,我在这里有一个修改过的版本

My modifications are on App/cdk-virtual-scroll-overview-example.css , where I have changed the css to contain the following.. 我的修改是在App/cdk-virtual-scroll-overview-example.css ,我在其中更改了css以包含以下内容。

.example-viewport {
      height: 200px;
      width: 90%;
      border: 1px solid black;
      display: flex;
      flex-direction:  row;
      flex-wrap:  wrap
    }

    .example-item {
      height: 50px;
      background: red;
      margin:0.5px;
      width: 33%
    }

      @media screen and (min-width: 360px)  {
       .example-item {
          width: 45%
         }
       }

So my aim here is have the items showing either 2 or 3 a row depending on the screen size. 所以我的目标是根据屏幕尺寸显示每行2或3行的项目。 However, as can be seen, they do not seems to wrap at all... 然而,可以看出,它们似乎根本没有包装......

在此输入图像描述

I have used flex here (have I done this wrong?), but any css to get it working will do (perhaps flex grid, or other) 我在这里使用过flex(我做错了吗?),但任何使用它的css都可以(也许是flex grid,或者其他)

Is this possible using the cdk-virtual-scroll ? 这可能使用cdk-virtual-scroll吗?

Thanks in advance 提前致谢

You could workaround it by chunking your items according to the number you want per row and then within the virtual scroll add ngFor to iterate each chunk. 您可以通过根据每行所需的数量对项目进行分块然后在虚拟滚动内添加ngFor来迭代每个块来解决此问题。 Then you can display flex on chunk div. 然后你可以在块div上显示flex。

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

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