我提交一个...
您要请求功能还是报告错误?
是否可以从 0 以外的其他索引开始拖动滚动?
当前的行为是什么?
现在,默认情况下,拖动滚动从第一个图像/组件开始。
改变行为的动机/用例是什么?
最好选择开始拖动滚动的索引(加载时)。
您实际上可以通过在 `ngAfterViewInit 块中调用moveTo
来实现设置初始索引。 确保使用 setTimeout(() => {...}, 0); 包装调用
例如:
@ViewChild('nav', {read: DragScrollComponent}) ds: DragScrollComponent;
ngAfterViewInit() {
setTimeout(() => {
this.ds.moveTo(3);
}, 0);
}
已经尝试过..,不幸的是我每次都会收到这个错误:
core.js:1673 ERROR TypeError: Cannot read property '_elementRef' of undefined
at DragScrollComponent.push../node_modules/ngx-drag-scroll/lib/ngx-drag-scroll.js.DragScrollComponent.maximumIndex (ngx-drag-scroll.js:415)
at DragScrollComponent.push../node_modules/ngx-drag-scroll/lib/ngx-drag-scroll.js.DragScrollComponent.moveTo (ngx-drag-scroll.js:214)
at myComponent.component.ts:141
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:3815)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (zone.js:496)
at ZoneTask.invoke (zone.js:485)
at timer (zone.js:2054)
你在ngAfterViewInit
块内调用moveTo
吗? 当拖动滚动轮播元素在页面上可见时,可以调用moveTo
方法。
或者您可以添加一点延迟,然后再试一次:
setTimeout(() => {
this.ds.moveTo(3);
}, 1000);
让我知道这是否有效。
我做到了。 但是现在超时时间为 1 秒! 感谢您的帮助,虽然它有点hacky。
嗯,不看代码我不知道为什么ngAfterViewInit
对你不起作用。 我会说现在使用setTimeout
,直到此功能结束。 PR 非常受欢迎。
您实际上可以通过在 `ngAfterViewInit 块中调用
moveTo
来实现设置初始索引。 确保使用 setTimeout(() => {...}, 0); 包装调用
例如:@ViewChild('nav', {read: DragScrollComponent}) ds: DragScrollComponent; ngAfterViewInit() { setTimeout(() => { this.ds.moveTo(3); }, 0); }
您好,请在文档中添加此功能。
如果我使用此解决方案,用户将看到第一个项目移动到特定项目的动画。
我会在下面提出建议。 你觉得行不行?
ngAfterViewInit(){
setTimeout(()=>{
this.ds.currIndex = 3;
this.ds._elementRef.nativeElement.children[0].scrollLeft = someValue;
}, 10);
}
最有用的评论
您实际上可以通过在 `ngAfterViewInit 块中调用
moveTo
来实现设置初始索引。 确保使用 setTimeout(() => {...}, 0); 包装调用例如: