简体   繁体   English

拖放干扰 Angular 7 CDK 中的滚动

[英]Drag and drop interfering with scroll in Angular 7 CDK

I have an Ionic app, which is built in angular, and thus has angular cdk drag and drop in it to rearrange a list.我有一个 Ionic 应用程序,它内置于 angular 中,因此具有 angular cdk 拖放功能以重新排列列表。 Drag and drop works great, however, on mobile, I cannot scroll at all.拖放效果很好,但是,在移动设备上,我根本无法滚动。 I believe the drag and drop gestures are eating up my scroll gestures.我相信拖放手势正在吃掉我的滚动手势。

I've attempted to set the cdkDragStartDelay to 5000 (milliseconds):我试图将 cdkDragStartDelay 设置为 5000(毫秒):

<cu-task-row
  cdkDrag
  [cdkDragData]="task"
  [cdkDragStartDelay]="5000"

It does delay the drag, but I still cannot scroll.它确实延迟了拖动,但我仍然无法滚动。

Is it possible to scroll and have drag and drop implemented in mobile using Angular cdk?是否可以使用 Angular cdk 在移动设备中滚动并实现拖放?

If you are starting the scroll from outside the drag and drop elements and it's still not working, you should check the CSS.如果您从拖放元素外部开始滚动,但仍然无法正常工作,则应检查 CSS。 In particular properties like position and display.特别是位置和显示等属性。 They may cause some unexpected results with scrolling if incorrectly set如果设置不正确,它们可能会导致滚动时出现一些意外结果

The only solution (if you stay with cdk) is that if you migrate up to Angular Material latest (^8.1.0).唯一的解决方案(如果您继续使用 cdk)是,如果您迁移到最新的 Angular Material (^8.1.0)。

Cdk DragDrop (Material) 7 and early 8 are blocking the scroll when you are dragging ( https://github.com/angular/components/issues/14273#issuecomment-442201350 ).当您拖动时,Cdk DragDrop (Material) 7 和 Early 8 会阻止滚动( https://github.com/angular/components/issues/14273#issuecomment-442201350 )。 However it is already resolved with autoscroll feature in ^8.1.0 ( https://github.com/angular/components/issues/13588 ).但是,它已经通过 ^8.1.0 ( https://github.com/angular/components/issues/13588 ) 中的自动滚动功能解决了。

So if you migrate up, you can try out the new autoscroll feature that works with simple containers (like div) close well, in addition scrolling with mouse wheel is enabled, but I couldn't make it work with material table for now (was not so much investigation).因此,如果您向上迁移,您可以尝试新的自动滚动功能,该功能适用​​于简单容器(如 div)关闭良好,此外还启用了使用鼠标滚轮滚动,但我现在无法使其与材料表一起使用(是没有那么多调查)。

If you create an online example, i could try to help you more.如果您创建一个在线示例,我可以尝试为您提供更多帮助。

If you wanna scroll works vertical you can do that, via using angular material version 8 this feature added on angular version 8.如果你想垂直滚动作品,你可以做到这一点,通过使用角度材料版本 8,这个功能在角度版本 8 中添加。

also you may face horizontal issue, i solved it via injecting document and using container id您也可能面临横向问题,我通过注入文档和使用容器 ID 解决了这个问题

import { DOCUMENT } from '@angular/common';
import {Inject } from '@angular/core';

constructor(@Inject(DOCUMENT) private document: Document) {}

onDragMoved(event) {
    if (event.delta.x === 1) {
        this.document.getElementById('container').scrollLeft += 10;
    } else {
        this.document.getElementById('container').scrollLeft -= 10;
    }
}

I took a look at these docs on my tablet just to try it out and I can scroll as long as I initiate the scroll from outside of the drag drop elements.我在平板电脑上查看了这些文档只是为了尝试一下,只要我从拖放元素外部启动滚动,我就可以滚动。 Have you tried adding some empty space around your drag drop elements to see if you can initiate a scroll then?您是否尝试在拖放元素周围添加一些空白区域,以查看是否可以启动滚动?

https://material.angular.io/cdk/drag-drop/overview https://material.angular.io/cdk/drag-drop/overview

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

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