特别声明:原创文章,禁止转载。
1.安装scroll-into-view-if-needed
npm iscroll-into-view-if-needed
2.封装指令
import { Directive, ElementRef, HostListener } from "@angular/core";
import scrollIntoView from 'scroll-into-view-if-needed'
@Directive({
selector: '[scrollInput]'
})
export class ScrollInputDirective {
constructor(private ele: ElementRef) {
}
@HostListener('ionFocus') inputFocusNow() {
setTimeout(() => {
scrollIntoView(this.ele.nativeElement, {
scrollMode: 'if-needed',
block: 'nearest',
inline: 'nearest',
})
}, 250);
};
}